Sprite visible, not visible

I have a student that cannot get the sprite visible property to work correctly. Here is the code.

so I think i know what your going for and put the revised comments below with this your program should work as intended

// it may be wise to relabel these variables, enforcing best practices early is good
var sprite = createSprite(200, 200);
var sprite2 = createSprite(200, 200);
// i assume these will be background layers so they need to be drawn first
// putting them in a group like this will make is simple
var backgrounds = createGroup();
// you'll probably want to add more so you'll probably need a foreground group
// to achive a person going swimming or perhaps standing at the beach
var foreground = createGroup();
// add foreground sprites here
function draw() {
  // draws the current background first
  // event visible code
  if (keyDown("space")) {
    sprite.visible = false;
    sprite2.visible = true;
  } else {
    text("Hold space to go swimming", 20, 200);
    sprite.visible = true;
    sprite2.visible = false;
  // additional foreground sprites if necessary
// drawSprites() is not continuos outside of the draw loop

tldr; drawSprites was not in the draw loop and wasn’t set up for possible foreground attributes

Best Varrience


Yep! @varrience is correct and gave some great ideas and tips! The heart of the issue is moving the drawSprite into the function draw(). To make sure the text appears, it will need to be placed before the text block.