Challenge to nebulae[i].pos.x to for loop

I thought for sure I had figured out the challenge to add nebulae[i].pos.x to the for loop. This challenge id described at the 7 minute mark in the video. My code didn’t match the answer exactly but it did have the intended effect. All nebulas appear and move across the screen as you would expect. But it also has as completely unintended consequence. My version of the code makes scarfy totally disappear. This is a tough one to figure out. I tried the instructor’s code… everything works. I use my code and scarfy disappears. Here’s my for loop:

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;

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

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

nebulae[i].frame = 0;

nebulae[i].runningTime = 0.0;

nebulae[i].updateTime = 0.0;

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

}

The only difference is the last line. Here is the instructors last line:
nebulae[i].pos.x = windowDimensions[0] + i * 300;

It seems like my code, even if it causes slightly different behavior on the nebula, shouldn’t have any effect at all on scarfy.

Now that I look at my own code… the nebula shouldn’t work… or they should not be spaced correctly. All of the nebula should be 1 pixel off from each other. But that’s not what happened.

Is tricky, but I can you give a simple answer. :slight_smile:

If we have 6 nebula and windowsDemension[0] for example 100 then…

base on you’r line → nebulae[i].pos.x = windowDimensions[0] += 300;
What it does?

  1. nebula[i].pos.x = 400
  2. Add to windowDimension[0] another 300.

so… at the end windowDimension[0] = 300 * 6 :slight_smile:
:slight_smile:
You need to recheck if when we check if scarfy is on ground :slight_smile:
Maybe you use a wrong window demension.
Becouse i used your code of changing window dimension in for loop and Scarfy is visibile.

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

Privacy & Terms