Segmentaion error scarfy

#include “raylib.h”

int main()

{

//window dimensions

const int winWidth{512};

const int winHeight{380};



int velocity{0};

//acceleration due to gravity (pixels/frame/frame)

const int gravity{1};

Texture2D scarfy = LoadTexture("textures/scarfy.png");

Rectangle scarfyRec;

scarfyRec.width = scarfy.width/6;

scarfyRec.height = scarfy.height;

scarfyRec.x = 0;

scarfyRec.y = 0;

Vector2 scarfyPos;

scarfyPos.x = winWidth/2 - scarfyRec.width/2;

scarfyPos.y = winHeight - scarfyRec.height;

//jump velocity

const int jumpVel{-22};

bool isinAir{};

//initialize window

InitWindow(winWidth, winHeight, "Dapper Dasher!");

SetTargetFPS(60);

while (!WindowShouldClose())

{

    //start drawing

    BeginDrawing();

    ClearBackground(WHITE);

    //ground check

    if (scarfyPos.y >= winHeight -scarfy.height)

    {

        //rectangle on ground

        velocity = 0;

        isinAir = false;

    }

    else

    {

        //rectangle in air

        velocity += gravity;

        isinAir = true;

    }

    //check for jumping

    if (IsKeyPressed(KEY_SPACE) && !isinAir)

    {  

        velocity += jumpVel;

    }

    // update position

    scarfyPos.y += velocity;

           

    //start texture

    DrawTextureRec(scarfy, scarfyRec, scarfyPos, WHITE);

    //stop drawing

    EndDrawing();

}

UnloadTexture(scarfy);

CloseWindow();

}

i figured it out, i put all his info before initailizing the window

Yup, specifically you cannot call LoadTexture before InitWindow, as that function enables access to video memory in your GPU (among other tasks).

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms