Student Game Needs Help with Backgrounds

The above game will not keep the one background when clicked on the sprite. We keep trying to switch the order of backgrounds but nothing is working. Please help!

Thanks!

I’m not exactly sure what the student wants but it seems like the background is changing after the initial change when the first click on the sprite in the collectItems function. I pasted a bit of it.

function collectItems() {
  if (robot.isTouching(token)) {
    token.visible = false;
    score = score + 1;
  }
  if (robot.isTouching(flag)) {
    flag.visible = false;
    /// ******** . switches background to #2 here. ************
    background2();
  }

Which background should be showing during the game?

She doesn’t know where to put background0 because the score is starting right away and just keeps increasing. Thank you!

Hi Erin,

Can you explain how the student wants the game to work? Which backgrounds should be displayed when? What should be happening with the score? I’m having a little trouble understanding what the goal is.

The biggest problem with the game is that there is a function named “score” and a variable named “score”, so they are conflicting. If the student fixes that, it will be a big help.

Thanks,
Elizabeth

From my experience with this, using visible is not the correct fix. When something is not visible, you can still interact with it. The better way to approach things is to have the particular sprite start off screen, with coordinates such as 500, then when you start the screen, put them in the location that you would like. This also applies to when you collect something like a flag, instead of turning the visibility off, move it off screen, that way you do not interact with it.

The only time I tell students to use visibility properties are with sprites that you do not interact with, such as a start screen or game winning screen.

1 Like

You are right! I think this is a big concept that needs to be mentioned or changed as it comes up as an issue a lot.