(Drawing From Sprite Sheets) Scarfy Not loading and I am not sure why

As the title said, Scarfy is not loading. I know this is a common problem with a wide variety of common solutions, but I am kinda in stump right now.

Here is my code, and any Help I could get would be great.

#include “raylib.h”

int main()

{

//Creating window size

//const makes the variable impossible to change

const int HeightW {1000};

const int WidthW {950};

//Gravity by acceleration based on ((pixles/frame)frame)

const int Gravity {1};

//Custom Variable from raylib. Compound data type

Texture2D Scarfy = LoadTexture(“dapper-dasher-master-textures/texture/scarfy.png”);

//Custom variable that will load the a section of the loaded png

Rectangle ScarfyRec;

//Since there is 6 images in one file we draw from, the width will be divided by 6

ScarfyRec.width = Scarfy.width/6;

//The Height is the same as loaded texture

ScarfyRec.height = Scarfy.height;

//The starting point on the image to be loaded is 0,0 on the top left of the screen

ScarfyRec.x = 0;

ScarfyRec.y = 0;

//Position for the draw texture pact

Vector2 ScarfyPostion;

//Putting the center of Scarfy to be in the center of the Window

ScarfyPostion.x = WidthW/2 - ScarfyRec.width/2;

ScarfyPostion.y = HeightW - ScarfyRec.height;

//Jumping velocity

const int jump {-13};

//Rectangle Example/

//const int RectH {25};

//const int rectW {100};

//Velocity and Position Variables

int Velocity {0};

//Position of the rectangle will appear at the Rectangle’s height, 100 pixles above the bottom of tg

//int PosY {HeightW - rectW};

bool InAir;

InitWindow(WidthW,HeightW,“Run,run, run as fast as you can”);

SetTargetFPS(60);

//Dont forget that '!' can negate a boolean

while(!WindowShouldClose())

{

//start drawing

BeginDrawing();

//creates the background color

ClearBackground(BLACK);



    //have to make sure that the starting position of the rectangle is on the bottom of the window

    //ground height, if the rectangle is sitting on the bottoom of the window

if (Scarfy.height >= HeightW - ScarfyRec.width)

{

    Velocity = 0;

    InAir = false;

}else

{

    //Rectangle is in the air

    //apply gravity per each frame of the while loop

    Velocity += Gravity;

    InAir = true;

}

//Checking for jumping

if(IsKeyPressed(KEY_SPACE)&& !InAir)

{

Velocity +=jump;

}



//updating the position each instance of the while loop

Scarfy.height += Velocity;

DrawTextureRec(Scarfy,ScarfyRec,ScarfyPostion,WHITE);

//Creating the rectangle

//DrawRectangle(WidthW/2, PosY, RectH,rectW,WHITE);

//ends the drawing

EndDrawing();

}

UnloadTexture(Scarfy);

CloseWindow();

}

Edit: sometimes, I make unique variable names as a way to take notes so that’s why they might be different then the instructors.

#include "raylib.h"

int main()
{
    //Creating window size
    //const makes the variable impossible to change
    const int HeightW {1000};
    const int WidthW {950};

    //Gravity by acceleration based on ((pixles/frame)frame)
    const int Gravity {1};

    // From Tuomo: This needs to be called before any LoadTexture calls, as this function makes graphics memory available for use
    InitWindow(WidthW,HeightW,"Run,run, run as fast as you can");

    //Custom Variable from raylib. Compound data type
    Texture2D Scarfy = LoadTexture("textures/scarfy.png");

    //Custom variable that will load the a section of the loaded png
    Rectangle ScarfyRec;

    //Since there is 6 images in one file we draw from, the width will be divided by 6
    ScarfyRec.width = Scarfy.width/6;

    //The Height is the same as loaded texture
    ScarfyRec.height = Scarfy.height;

    //The starting point on the image to be loaded is 0,0 on the top left of the screen
    ScarfyRec.x = 0;
    ScarfyRec.y = 0;

    //Position for the draw texture pact
    Vector2 ScarfyPostion;

    //Putting the center of Scarfy to be in the center of the Window
    ScarfyPostion.x = WidthW/2 - ScarfyRec.width/2;
    ScarfyPostion.y = HeightW - ScarfyRec.height;

    //Jumping velocity
    const int jump {-13};

    //Rectangle Example/

    //const int RectH {25};

    //const int rectW {100};

    //Velocity and Position Variables
    int Velocity {0};

    //Position of the rectangle will appear at the Rectangle’s height, 100 pixles above the bottom of tg

    //int PosY {HeightW - rectW};
    bool InAir;
    SetTargetFPS(60);

    //Dont forget that '!' can negate a boolean
        while(!WindowShouldClose())
        {
            //start drawing
            BeginDrawing();

            //creates the background color
            ClearBackground(BLACK);
                //have to make sure that the starting position of the rectangle is on the bottom of the window
                //ground height, if the rectangle is sitting on the bottoom of the window
            if (ScarfyPostion.y >= HeightW - ScarfyRec.width) //From Tuomo: ScarfyPostion.y instead of Scarfy.height
            {
                Velocity = 0;
                InAir = false;
            }else
            {

                //Rectangle is in the air
                //apply gravity per each frame of the while loop
                Velocity += Gravity;
                InAir = true;
            }

            //Checking for jumping
            if(IsKeyPressed(KEY_SPACE)&& !InAir)
            {
                Velocity +=jump;
            }



            //updating the position each instance of the while loop
            ScarfyPostion.y += Velocity; //From Tuomo: ScarfyPostion.y instead of Scarfy.height
            DrawTextureRec(Scarfy,ScarfyRec,ScarfyPostion,WHITE);
            //Creating the rectangle
            //DrawRectangle(WidthW/2, PosY, RectH,rectW,WHITE);
            //ends the drawing
            EndDrawing();
        }

    UnloadTexture(Scarfy);
    CloseWindow();
}

I added comments in this code to where your errors where, but to quickly point them out:

  • You need to call InitWindow() before you can use LoadTexture(), as InitWindow opens up access to video memory which we would not have access to beforehand.
  • You’re making use of Scarfy.height when you should be using ScarfyPotistion.y later in when doing your code for jumping. This is going to have the somewhat comedic side-effect of stretching out Scarfy instead of jumping.

Thank you for those solutions, I added them in and Scarfy still isn’t showed up

Update: Had the wrong file path I had
“dapper-dasher-master-textures/texture/scarfy.png”

instead of
“dapper-dasher-master-textures/textures/scarfy.png”

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

Privacy & Terms