Text not showing in Game Lab when a sprite is used as a background

Dear friends,

When a sprite is used as a background, it seems that text is always below the level of the background sprite no matter how the code is arranged.

Any ideas please?

Thanks in advance!

Clement

Link to the project or level: Code.org - Game Lab

What I expect to happen: Text to be displayed / change when laser touches an alien.

What actually happens: Expected action doesn’t happen

What I’ve tried: Placing text in various parts of the code (before Draw Loop, etc.)

Hi @clcheah,
Could you please post the Share link to the project in question? I know this is a common issue people have had. Having the specific link will help us better find the issue causing the problem.

Also, here is a post from a previous question on the forum that may help.

@clcheah ,

I took a look at the project and the last action is to draw the sprites. Since the background is a sprite, it is drawn on top of the text. You might want to try to draw the text last (below the drawSprites block) as order matters, even inside the draw loop.

Good luck!

Mike

I get this issue a lot. As Mike suggested, first thing to try is putting text command below drawsprites command in draw loop. However, sometimes that does not do what you want. I see this problem occur many times when trying to write text like “You WIN” or “You Lose” depending on the score. I suggest 2 things to students:

Take a background sprite and modify it to add the text you want, for example, WIN or LOSE. Note, for some reason, there is no text tool in the animation editor.

Second is only to drawsprites when game is not lost or won. Here’s a code example of that.

var main = createSprite(200, 200);
var char = createSprite(200, 200);
char.setAnimation(“virus02_04_1”);
char.scale = 0.25;
main.setAnimation(“abstract_08_1”);
var score = 0;
fill(“black”);
textSize(32);
function draw() {
score = score + 1;
if (score > 50) {
background(“white”);
text(“WINNER!”, 100, 100);
} else {
drawSprites();
text("Score: " + score , 21, 50);
}
}

1 Like