Draw text on sprite location
-
Hi everyone!
I need some help...
How can I draw text on a sprite location?
I want to show the damage inflected to an enemy when the enemy gets hit.Thanks in advance!
-
@skullo Well you could use a text sprite (https://fuzearena.com/help/view/setSpriteText) or you can use drawText( x, y, size, color, values)
-
@pianofire thanks for your answer. I was playing with drawText and drawTextEx but these functions take as coordinates the display screen, right? If I use getSpriteLocation(enemy) as coordinates the text is not displayed on the enemy location.
-
@skullo You are correct. The draw functions take screen coordinates, the sprites operate on sprite/map coordinates. You can poll the current transformation between them with getSpriteCamera(). If there are no rotations and you are drawing to the screen, here is how you can convert sprite to screen coordinates:
function sprite_to_screen(sprite_coordinates) c = getSpriteCamera() // apply translation and zoom screen_coordinates_from_center = (sprite_coordinates - {c.x, c.y}) * c.z // that is from the center of the screen, real screen coordinates are from the corner return screen_coordinates_from_center + {.5,.5} * {gWidth(), gHeight()}
I would recommend the text sprite method, though. I did not know it exists myself and it's going to solve a small annoying problem with draw priority I have right now!
-
@z-mann Your function works, thanks a lot!!!
I was playing with setSpriteText, it does its job but I'm not able to change the text font as I can with drawTextEx.
-
@skullo I guess you could also use the setDrawTarget method to drawtext to a sprite
-
It would be nice if you would add font support for setSpriteText() in the future! Fingers crossed.
-
-
That looks neat!