drawText() fails to overwrite
-
If I draw the same text in the same place twice, first in a foreground colour and then in a background colour. I still see a "ghost outline" of the foreground colour...
text = "Hello World!" text_size = 300 textSize(text_size) text_width = textWidth(text) text_height = gHeight() / tHeight() drawText(gWidth() / 2 - text_width / 2, gHeight() / 2 - text_height / 2, text_size, skyblue, text) drawText(gWidth() / 2 - text_width / 2, gHeight() / 2 - text_height / 2, text_size, black, text) update() sleep(2)
Shouldn't it disappear?
-
You will have to add a clear() function to clear the screen between updates if you want it to overwrite.
-
Dave is of course correct regarding the use of clear. But I was just exchanging messages with @pianofire on the subject since I was a little confused too and it is most likely due to anti-aliasing being applied to font rendering in the frame buffer.
@pianofire very quickly produced some very lovely effects by just offsetting the black slightly from the lighter colour though so I can see a lot of advantages to the way that it is!
-
I would love to see some of these text effects, and use them in my text adventure! @Martin @pianofire
-
@Martin - the weird edge effect certainly allows for some nice patterns when in a loop!
In my case the screen has a lot of static stuff on that I don't want to re-draw (it's the "options" screen for my game) so I didn't want to use "clear()". I just wanted to animate a few small bits of text so now I just use "box()" in background colour...text = "Hello World!" text_size = 300 textSize(text_size) text_width = textWidth(text) text_height = gHeight() / tHeight() drawText(gWidth() / 2 - text_width / 2, gHeight() / 2 - text_height / 2, text_size, skyblue, text) // drawText(gWidth() / 2 - text_width / 2, gHeight() / 2 - text_height / 2, text_size, black, text) box(gWidth() / 2 - text_width / 2, gHeight() / 2 - text_height / 2, text_width, text_height, black, false) update() sleep(2)
This should allow for some nice (or annoying!) animation effects using size, transparency and position.... I haven't tried yet, but maybe "pulse", "wiggle" and "slide"?
-
Apologies @Wanderer1412 I didn't give enough thought to this post! After seeing some of these effects I regret simply advising a
clear()
! -
@Wanderer1412 You could still have your static text while using clear by putting the static text in a function and simply calling that from the main loop. Obviously there will come a point where you may start to see slow-down and then the box approach would help with that. There's always more than one way to achieve the same thing.
-
@Martin - Understood, and both approaches would work. Thanks so much for all your input. I'm not sure how I got the whim to animate bits of text - but it turned out to be a lot more fun than I expected and has opened up new possibilities!
-
I finally got back to the program where I used the animated text discussed above. For anyone who is curious it's called "Pong+" and shared with friend code SW-3411-8656-9702
The title-screen uses the clear() method that Dave suggested originally, and the select-score-to-win-screen uses my "black box" method (to avoid re-drawing the whole screen)