Popup Text Effect

Hi there,

I have been thinking of this for a while in my head and am attempting to fulfill it, however I am having trouble. Here is what I am looking for:

Setup: You know whenever you collect a coin… or a gem, or maybe just gain some XP, a little text pops up that says something like “+1”, or “+50”? That is what I’m attempting to visually achieve.

However, I want to be able to simplify it by creating a method for it in an FX class. So that it could be called using something like “text(”+50", x, y) and be drawn correctly in the sprite batch. The attempt I just made failed. What I tried was:

Play Screen (Play), FX CLass (FX).

(Play) 
render method..
game.sb.begin();
fx.text("Hello", 50, 50);
game.sb.end();

(FX)
text method
text(String text, i, ii){
fontX = i;
fontY = ii;

//Create TTF Font

font.draw(game.sb, fontX, fontY);

(All using the same spritebatch from main class)

Hopefully this makes sense. Please help me out.
Thanks - A

I’ll not code it for you now because I’m not at home but I’ll explain what you need to do:

You need a textpopup class to hold the string and an x,y. This class will also have an update method that increments the y coordinate (or decrements it) moving it up or down the way you want it.

Then you’ll probably want a static list of textpopups. When you call your text(“thing”,x,y), you’ll add an instance of textpopup with those parameters to your list. Then you add an FX.update static method to update your list (you iterate through each element and call update on them).

With this you handled adding and moving your text popups. You still have to handle deleting them or fading them out. To do that you can add an internal timer to each popup element and counting them out. And also have a active state to each popup that you use to remove them from the popuplist.

Or you can use another algorithm in the FX update method… Thats up to you. If you need some code to understand this, tell me and I’ll help you =)

Yea, that is definitely the way I figured possible… the only thing is rendering the text in a screen classes sprite batch. It needs to draw the specific string told to…

I’m not sure I understand what you said, but if you mean how to draw each popup, make a render method and while you update the popuplist, also call that render method with a started valid sprite batch. Libgdx confuses updating and rendering anyway…