Hello,
Several of my students are trying to make text appear when a condition is met, but the text is not appearing. Can anyone help me with this code to see why the text is not appearing? Thank you in advance. I put a little space around the part we are struggling with. Everything works except the text appearing.
var pinetrees = createSprite(200, 200);
pinetrees.setAnimation(“pinetrees”);
var kangawoo = createSprite(200, 80);
kangawoo.setAnimation(“kangawoo”);
var pondah = createSprite(330, 250);
pondah.setAnimation(“pondah”);
kangawoo.scale = 0.3;
pondah.scale = 0.3;
var trex = createSprite(215, 265);
trex.setAnimation(“trex”);
trex.scale = 0.3;
var bear = createSprite(68, 204);
bear.setAnimation(“bear”);
bear.scale = 0.3;
function draw() {
Thanks! I finally figured out what the problem was. The background was a sprite, so it was overwriting the text each time the loop refreshed. We first tried drawing a background in the conditional. But, it still didn’t work until we moved the draw sprite to the top of the loop. By moving the draw sprite to the top of the loop, the text became visible. This has fixed all of the text issues my students have been having.
It sounds like the challenge the students are having is that they want things to disappear and stay disappeared after a key has ben pressed. The problem is probably that the text doesn’t get drawn on the iteration of the draw loop when the key is pressed, but that on the next iteration, because the key isn’t pressed anymore, the text is drawn again. You might have to use a variable to save the information about whether the text should be drawn or not. That would involve at least two conditionals. The first conditional would set a drawText variable to false when user input is detected, and the second conditional would draw the text when drawText variable is true.
If that’s not what you’re looking for, maybe you can share a link to the student code so we can see what’s going on.