Visible property not working in if statements in draw function

I’m not sure why the note will not disappear from one if statement to another when we press the letter ‘d’ then ‘r’? Anyone know if it is something with the sprite.visible or the draw function I don’t know? any help would be great. Thank you.

//Instruments
var drums = createSprite(100,200);
drums.setAnimation(“drum_set_1”);
drums.scale = 0.7;
var strings = createSprite(300,275);
strings.setAnimation(“electric_guitar_1”);
strings.scale = 0.7;

//Notes
var note1 = createSprite(50,50);
note1.setAnimation(“eighth_note_1”);
note1.scale = 0.3;
note1.visible = false;

//Loop
function draw(){
if (keyDown(“d”)){
note1.visible = true;
playSound(“sound://category_instrumental/digital_drum_repeating.mp3”);
}

if (keyDown(“r”)){
note1.visible = false;
playSound(“sound://category_instrumental/trumpet.mp3”);
}

drawSprites();
}

Hi @jdagostino,

Welcome to the forum! Game Lab works in frames and the draw loop draws those frames about 30x per second. In order to see when something disappears in a frame you have to draw “over” the previous frame using the background block (which I always place at the top of the draw loop).
image

Hope that helps!
~Michelle

1 Like

It did thank you! It worked right after I did that.

1 Like