Issue with Scarfy Sprite

Not sure why it is doing it, but I’ve followed along and have the exact same code as the course, but for some reason my scarfy says it’ loaded, but doesn’t appear after I added the nebula. any ideas as to why?

Hi Silencesdc,

It’ll really help us out if you can show us your code. Particularly the section for setting up and drawing Scarfy. But the whole code wouldn’t hurt, either.

Here is the entire code so far that I’ve done. Not finished with the course yet, but Enjoying it.

#include “raylib.h”

int main()

{

// Window Dimentions

const int w_width{512};

const int w_height{380};

// Initialize the Window

InitWindow(w_width, w_height, "Dapper Dasher!");

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

const int gravity{1'000};

// jump velocity (pixels/second)

const int jumpVel{-600};

bool isInAir{};

// nebula variables

Texture2D nebula = LoadTexture("textures/12_nebula_spritesheet.png");

Rectangle nebRec{0.0, 0.0, nebula.width/8.0f, nebula.height/8.0f};

Vector2 nebPos{w_width, w_height - nebRec.height};

// nebula animation variables

int nebFrame{};

const float nebUpdateTime{1.0/12.0};

float nebRunningTime{};

// nebula x velocity (pixels/second)

int nebVel{-200};

// scarfy variables

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 = w_width/2 - scarfyRec.width/2;

scarfyRec.y = w_height - scarfyRec.height;



// animation frame

int frame{};

// update time

const float updateTime{1.0/12.0};

float runningTime{};

// rectangle dimensions

int velocity{0};

SetTargetFPS(60);

while (!WindowShouldClose())

{

    // delta time (time since last frame)

    const float dT{GetFrameTime()};

    // Start Drawing

    BeginDrawing();

    ClearBackground(WHITE);

    // ground check

    if (scarfyPos.y >= w_height - scarfyRec.height)

    {

        // rectangle is on the ground

        velocity = 0;

        isInAir = false;

    }

    else

    {

        // retangle is in the air

       

        // apply gravity

        velocity += gravity * dT;

        isInAir = true;

    }

    if (IsKeyPressed(KEY_SPACE) && !isInAir)

    {

        velocity += jumpVel;

    }

    // update nebula position

    nebPos.x += nebVel * dT;

    // update scarfy position

    scarfyPos.y += velocity * dT;

    // update scarfy's animation frame

    if (!isInAir)

    {

            // update running time

        runningTime += dT;

        if (runningTime >= updateTime)

        {

            runningTime = 0.0;

            // update animation frame

            scarfyRec.x = frame * scarfyRec.width;

            frame++;

            if (frame > 5)

            {

                frame = 0;

            }

        }

    }

    // update nebula animation frame

    nebRunningTime += dT;

    if (nebRunningTime >= nebUpdateTime)

    {

        nebRunningTime = 0.0;

        nebRec.x = nebFrame * nebRec.width;

        nebFrame++;

        if (nebFrame > 7)

        {

            nebFrame = 0;

        }

    }

   

    // draw nebula

    DrawTextureRec(nebula, nebRec, nebPos, WHITE);

    // draw scarfy

    DrawTextureRec(scarfy, scarfyRec, scarfyPos, WHITE);

    // Stop Drawing

    EndDrawing();

}

UnloadTexture(scarfy);

UnloadTexture(nebula);

CloseWindow();

}

Should be

scarfyPos.y = w_height - scarfyRec.height;

Can’t believe I missed that. Guess it’s the only having 1 day off every 2 weeks, graveyard and trying to do courses and re-learn coding when I can. haha. Much appreciated, Thank you.

You’re welcome! Even if you were doing this 5 days a week, sometimes a second set of eyes is all that’s needed!

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

Privacy & Terms