My Nebula (hazard) stopped working!


I can’t figure out the issue as the compiler is not showing any errors, so there must be logical errors, but I cannot locate them. My hazards are not showing on the screen.

My code is: Dasher.cpp

Thank you in advance.

It looks like you are dividing the hazard’s position height by 8, on lines 41 and 42. They should just be: screenHeight - hazard1.sourceRectangle.height

SmackTubby has it right, but let me explain why. First, here are lines 41 and 42.

AnimData hazard1 {{0.0, 0.0, hazard.width/8, hazard.height/8}, {screenWidth, screenHeight - hazard1.sourceRectangle.height}, 0, 1.0/12.0, 0.0};
AnimData hazard2 {{0.0, 0.0, hazard.width/8, hazard.height/8}, {screenWidth + 300.0, screenHeight - hazard1.sourceRectangle.height}, 0, 1.0/16.0, 0.0};

The setup for AnimData works as follows:
AnimData data {{sprite source}, {position on screen}, starting frame, frame rate, frame running time}

For the position on the screen, in particular the y-position, you use screenHeight - hazard1.sourceRectangle.height / 8. Which translates to:

768 - (100 / 8) or 768 - 12.5, which is 755.5. This places most of the Nebula sprite outside of the screen, making it difficult if not impossible to see.

Thank you both. I understood the issue and solved it :slight_smile:

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

Privacy & Terms