I was wondering how I would go about making some flashing text for a game-over screen that reads "press z to try again". I tried using modulo however when I attempted this it would display the text for one frame and then show (about) 30 empty frames.
Any help on a simple and effective method would be greatly appreciated.
You can use something like this to achieve this effect:
blink_timer=0 blink_flag=false function _draw() cls() if (blink_flag) print "hello" if (blink_timer % 30 == 0) blink_flag=not blink_flag blink_timer+=1 end |
or some binary magic:
if (band(frame,32)!=0) print "hello" frame+=1 |
will blink ~ every second @60hz (use 16 @30fps)
Here's my super simplistic method for random flashing color text....
PRINT ("GAME OVER",50,50,RND(16))
But I have been wondering how to get text to flash back and forth between 2 colors, like red and blue... for example.
BAND is a powerful command I must admit. I need to explore it at some point. However, I tend to use MOD for my timing works.
cls() n=0 circfill(0,0,90,5) -- show overlay effect repeat color(0) if (n%16<8) color(7) print("g a m e",48,60) print("o v e r",48,68) color(n*8) print("press z to try again",24,76) flip() n+=1 until btn(4) |
Tiny additional point that actually resetting the counter avoids weirdness at the integer overflow boundary:
n = (n + 1) % 10 color(n == 0 and 1 or 7) |
Technically this is also avoided if your frame count is a power of 2, but so far I've found I want more control than that. Resetting also means maintaining a separate counter per effect, which may or may not meet your needs.
Good point, DDDaaannn. It is possible to let my demo run undisturbed for 18-minutes, yeah, after that it will likely mess up.
[Please log in to post a comment]