CSD Unit 3 Text Visibility

I have some students who are working on the project in lesson 14 and want to know how to make their text appear and then disappear. Any suggestions on how we could do this? Thanks!

The problem with text is that there is no .visible property that you can use. There are two main approaches my students have found successful.

The first method requires you to think about when you want the text to be present and write a conditional to make it so the text is only drawn at all when (something) is true. For example, if you want the text to disappear when a sprite moves off the left side of the screen, you could do something like this inside the draw loop:

if(sprite.x > 0) {
  text("Move the sprite off the screen",0,50);
}

The second method involves creating a variable to track whether the text should be visible or not. If something happens that should make the text appear or disappear, change the value If you want text to appear, but only until the user clicks the screen, you could do something like:

var textVisible = true;
function draw(){
  if(mouseWentDown("leftButton"){
    textVisible = false;
  }
  if(textVisible){
    text("Click the screen",0,50);
  }
}

Hope that helps!

5 Likes

Thank you so much!! We were wondering how to work around the no visibility for text.

This might sound silly, but I also taught my students how to make their text into a sprite by creating a PowerPoint of their text and saving it as a jpg which they can upload into Code Studio as a sprite. Then the visibility works. Some found success using this, but it’s not exactly using the code.

2 Likes

That sounds like a great idea too! Thanks!

Yeah I was wondering how to do this too. The PPT idea is a pretty good idea. For me in my conditional I just changed the background and that overlapped my text. It worked for my idea, but would be nice to find an actual solution to make it disappear.

Mike,
A couple of my students have tried the first example and I have looked at their code and it just put another set of text on the screen

Could you post a link to the code from these students? That would make it easier to help with debugging.

1 Like