Nebula not visible

My nebulas are not visible and my character has no obstacle to jump from.
Here is my entire code:

#include “raylib.h”

struct AnimData
{
Rectangle rec;
Vector2 pos;
int frame;
float UpdateTime;
float runningTime;
};

int main()
{
// array with window dimensions
int windowDimensions[2];
windowDimensions[0] = 512;
windowDimensions[1] = 380;

InitWindow(windowDimensions[0], windowDimensions[1], "Dapper Dasher!");

// acceleration due to gravity (pixels/frame/)/s
const int gravity{1'000};

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

const int sizeOfNebulae{6};
AnimData nebulae[sizeOfNebulae]{};

for (int i = 0; i < sizeOfNebulae; i++ )
{
    nebulae[i].rec.x = 0.0;
    nebulae[i].rec.y = 0.0;
    nebulae[i].rec.width = nebula.width/8.0f;
    nebulae[i].rec.width = nebula.height/8.0f;
    nebulae[i].pos.y = windowDimensions[1] - nebula.height/8.0f;
    nebulae[i].pos.x = windowDimensions[0] + i * 300;
    nebulae[i].frame = 0;
    nebulae[i].runningTime = 0.0;
    nebulae[i].UpdateTime = 1.0/16.0;
}

// nebula X velocity (pixels/second)
int nebVel{-200};

// scarfy variables
Texture2D scarfy = LoadTexture("textures/scarfy.png");
AnimData scarfyData;
scarfyData.rec.width = scarfy.width/6;
scarfyData.rec.height = scarfy.height;
scarfyData.rec.x = 0;
scarfyData.rec.y = 0;
scarfyData.pos.x = windowDimensions[0]/2 - scarfyData.rec.width/2;
scarfyData.pos.y = windowDimensions[1] - scarfyData.rec.height;
scarfyData.frame = 0;
scafyData.UpdateTime = 1.0/12.0;
scarfyData.runningTime = 0.0;

// is the rectangle in the air?
bool isInAir{};
 // jump velocity(pixels/second)
const int jumpVel{-600};

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 (scarfyData.pos.y >= windowDimensions[1] - scarfyData.rec.height)
    {
       // rectangle is on the ground
       velocity = 0;
       isInAir = false;
    }
    else
    {
        // rectangle is in the air
         velocity += gravity * dT;
         isInAir = true;
    }
    // check for jumping
    if (IsKeyPressed(KEY_SPACE) && !isInAir)
    {
        velocity += jumpVel;
    }

    for (int i = 0; i < sizeOfNebulae; i++)
    {
     // update each nebula position
     nebulae[i].pos.x += nebVel * dT;
    }

    // update scarfy position
    scarfyData.pos.y += velocity * dT;

   // update scarfy's animation frame
   if(!isInAir)
   {
        // update running time
    scarfyData.runningTime += dT;
    if (scarfyData.runningTime >= scarfyData.UpdateTime)
    {
        scarfyData.runningTime = 0.0;
          // update animation frame
    scarfyData.rec.x = scarfyData.frame * scarfyData.rec.width;
    scarfyData.frame++;
    if (scarfyData.frame > 5)
    {
        scarfyData.frame = 0;
       }
     }
   } 

   for (int i = 0; i < sizeOfNebulae; i++)
   {
       // update nebula animation frame
    nebulae[i].runningTime += dT;
    if (nebulae[i].runningTime >= nebulae[i].UpdateTime)
    {
        nebulae[i].runningTime = 0.0;
          if (nebulae[i].frame > 7)
    nebulae[i].rec.x = nebulae[i].frame * nebulae[i].rec.width;
        nebulae[i].frame++;
          {
            nebulae[i].frame = 0;
        }
    }
   }
   
    for (int i = 0; i < sizeOfNebulae; i++)
    {
        // draw both nebula
        DrawTextureRec(nebula, nebulae[i].rec, nebulae[i].pos, WHITE);
    }

    // draw scarfy
    DrawTextureRec(scarfy, scarfyData.rec, scarfyData.pos, WHITE);

    // stop drawing
    EndDrawing();

}
UnloadTexture(scarfy);
UnloadTexture(nebula);
CloseWindow();

}

Hi Bea8st,

I’ve spotted a few errors, but first the one with the nebulae themselves (which oddly enough I spotted last).

When initializing the nebulae, you set their rec.width twice:

nebulae[i].rec.width = nebula.width/8.0f;
nebulae[i].rec.width = nebula.height/8.0f;

This is simply fixed by changing the second line to be nebulae[i].rec.height instead.

Next, I believe the scafy in scafyData.UpdateTime = 1.0/12.0; should be scarfy. Small typo there.

Lastly, this bit of code has some if it outside of the if-statement and is otherwise not formatted correctly. So replace this:

if (nebulae[i].frame > 7)
    nebulae[i].rec.x = nebulae[i].frame * nebulae[i].rec.width;
        nebulae[i].frame++;
          {
            nebulae[i].frame = 0;
        }

With this:

if (nebulae[i].frame > 7)
{
    nebulae[i].rec.x = nebulae[i].frame * nebulae[i].rec.width;
    nebulae[i].frame++;
    nebulae[i].frame = 0;
}

Thank you for giving out some errors but there is now another error I cant figure out.
It says that it expects a ‘}’ at the end of the input which is the line 153 where my code ends.
It already has a ‘}’ so I don’t know what the error is about.

That means you have an extra { somewhere

Ive looked but I think I see the problem here.
Here is the code(the problem might be all the way down but I’m gonna send the full code just in case):

#include “raylib.h”

struct AnimData

{

 Rectangle rec;

 Vector2 pos;

 int frame;

 float UpdateTime;

 float runningTime;

};

int main()

{

// array with window dimensions

int windowDimensions[2];

  windowDimensions[0] = 512;

  windowDimensions[1] = 380;

InitWindow(windowDimensions[0], windowDimensions[1], "Dapper Dasher!");

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

const int gravity{1'000};

// nebula variables

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

const int sizeOfNebulae{6};

AnimData nebulae[sizeOfNebulae]{};

for (int i = 0; i < sizeOfNebulae; i++ )

{

    nebulae[i].rec.x = 0.0;

    nebulae[i].rec.y = 0.0;

    nebulae[i].rec.width = nebula.width/8.0f;

    nebulae[i].rec.height = nebula.height/8.0f;

    nebulae[i].pos.y = windowDimensions[1] - nebula.height/8.0f;

    nebulae[i].pos.x = windowDimensions[0] + i * 300;

    nebulae[i].frame = 0;

    nebulae[i].runningTime = 0.0;

    nebulae[i].UpdateTime = 1.0/16.0;

}

// nebula X velocity (pixels/second)

int nebVel{-200};



// scarfy variables

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

AnimData scarfyData;

scarfyData.rec.width = scarfy.width/6;

scarfyData.rec.height = scarfy.height;

scarfyData.rec.x = 0;

scarfyData.rec.y = 0;

scarfyData.pos.x = windowDimensions[0]/2 - scarfyData.rec.width/2;

scarfyData.pos.y = windowDimensions[1] - scarfyData.rec.height;

scarfyData.frame = 0;

scarfyData.UpdateTime = 1.0/12.0;

scarfyData.runningTime = 0.0;



// is the rectangle in the air?

bool isInAir{};

 // jump velocity(pixels/second)

const int jumpVel{-600};

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 (scarfyData.pos.y >= windowDimensions[1] - scarfyData.rec.height)

    {

       // rectangle is on the ground

       velocity = 0;

       isInAir = false;

    }

    else

    {

        // rectangle is in the air

         velocity += gravity * dT;

         isInAir = true;

    }

    // check for jumping

    if (IsKeyPressed(KEY_SPACE) && !isInAir)

    {

        velocity += jumpVel;

    }

    for (int i = 0; i < sizeOfNebulae; i++)

    {

     // update each nebula position

     nebulae[i].pos.x += nebVel * dT;

    }

   

    // update scarfy position

    scarfyData.pos.y += velocity * dT;



   // update scarfy's animation frame

   if(!isInAir)

   {

        // update running time

    scarfyData.runningTime += dT;

    if (scarfyData.runningTime >= scarfyData.UpdateTime)

    {

        scarfyData.runningTime = 0.0;

          // update animation frame

    scarfyData.rec.x = scarfyData.frame * scarfyData.rec.width;

    scarfyData.frame++;

    if (scarfyData.frame > 5)

    {

        scarfyData.frame = 0;

       }

     }

   }

for (int i = 0; i < sizeOfNebulae; i++)

{

       // update nebula animation frame

    nebulae[i].runningTime += dT;

    if (nebulae[i].runningTime >= nebulae[i].UpdateTime)

    {

        nebulae[i].runningTime = 0.0;

          if (nebulae[i].frame > 7)

            {

                nebulae[i].rec.x = nebulae[i].frame * nebulae[i].rec.width;

                nebulae[i].frame++;

                nebulae[i].frame = 0;

            }

                   

    for (int i = 0; i < sizeOfNebulae; i++)

    {

        // draw both nebula

        DrawTextureRec(nebula, nebulae[i].rec, nebulae[i].pos, WHITE);

    }

    // draw scarfy

    DrawTextureRec(scarfy, scarfyData.rec, scarfyData.pos, WHITE);

    // stop drawing

    EndDrawing();

}

UnloadTexture(scarfy);

UnloadTexture(nebula);

CloseWindow();

}

You’re missing a closing brace for the if(nebulae[i].runningTime >= nebulae[i].UpdateTime) block of code and for the for(int i = 0; i < sizeOfNebulae; i++) block of code.

for (int i = 0; i < sizeOfNebulae; i++)
{
    // update nebula animation frame
    nebulae[i].runningTime += dT;
    if (nebulae[i].runningTime >= nebulae[i].UpdateTime)
    {
        nebulae[i].runningTime = 0.0;
        if (nebulae[i].frame > 7)
        {
            nebulae[i].rec.x = nebulae[i].frame * nebulae[i].rec.width;
            nebulae[i].frame++;
            nebulae[i].frame = 0;
        }
    }   // Here       
}  //And here

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

Privacy & Terms