Combat text updates

week5- Work is progressing nicely on my game. (a Realtime squad thing)
Starting to add some text to keep track of player status, etc.

Very basic question:
If I’m putting in combat text, (i.e. “Max has hit Thug for 5 pts of damage”), what’s the best way to clear and update this?

That is… if I just send text to that area of the screen again it obviously overwrites what was there below ans is illegible. So what’s a good way to implement “combat text” type displays. Should I be using a specific directgui control? is there a way to clear text from what I put up on the screen? or some other method?

just define an OnscreenText object, use his setText method to change your text message and you’ll be ok.

thx for the reply, but I think I did a poor job of asking my question.

I could be wrong and I don’t have my code with me (my job frowns on my working on my game while I’m at work - imagine that! :slight_smile: ) - but I think I was using onscreentext and as it “writes over” my last text msg - i get something unreadable after 2 calls to it.

is there a way to clear the text without destroying the object? thx!

You might want to look into having a text movement interval where after created on the desired spot, it floats up then clears itself. This way if text shows up one after another, both messages should still be legible, and it takes care of the messy cleanup. Be careful with frequently updating onscreen text changes though…it will affect your fps depending on how many and how often.


if you ain’t done some nasty stuff in your code, calling yourtexobject.setText(‘shout!’) you’ll have your text refreshed as you wish - I could be wrong but I bet 2 cent on that you have ‘forgotten’ the onscreentext instancing inside the task callback where you assign the combat messages.

Do note that text generation is very slow and you shouldn’t generate large chunks of text every frame.

Thanks to all for the help. setText does work the way I needed it.

My problem was that I was calling Onscreentext as a function (probably got it from some sample that just had static text) adn it was never set up as an object whose msg i can change with setText.

I’ve got it all setup now and it works fine. (and I’m calling it on certain events not every frame, but thx for the heads-up on the performance hit)

calling Onscreentext - a python class - as a function as you said, means to instance that class therefore you were replicating that object n times and that explain why you saw multiple strings of text overlapping one above the other