Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Draw text on sprite location

    Help
    4
    9
    669
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Skullo
      Skullo last edited by

      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!

      pianofire 1 Reply Last reply Reply Quote 0
      • pianofire
        pianofire Fuze Team @Skullo last edited by

        @skullo Well you could use a text sprite (https://fuzearena.com/help/view/setSpriteText) or you can use drawText( x, y, size, color, values)

        Skullo 1 Reply Last reply Reply Quote 4
        • Skullo
          Skullo @pianofire last edited by

          @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.

          Z-Mann 1 Reply Last reply Reply Quote 0
          • Z-Mann
            Z-Mann @Skullo last edited by

            @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!

            Skullo 1 Reply Last reply Reply Quote 3
            • Skullo
              Skullo @Z-Mann last edited by

              @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.

              pianofire 1 Reply Last reply Reply Quote 0
              • pianofire
                pianofire Fuze Team @Skullo last edited by

                @skullo I guess you could also use the setDrawTarget method to drawtext to a sprite

                1 Reply Last reply Reply Quote 2
                • vinicity
                  vinicity F last edited by

                  It would be nice if you would add font support for setSpriteText() in the future! Fingers crossed.

                  1 Reply Last reply Reply Quote 0
                  • Skullo
                    Skullo last edited by

                    This is how it finally looks like:

                    1 Reply Last reply Reply Quote 2
                    • vinicity
                      vinicity F last edited by

                      That looks neat!

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post