CSD Unit 3 Text Visibility

csdunit3
lesson14

#1

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!


#2

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!


#3

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


#4

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.


#5

That sounds like a great idea too! Thanks!