Jump to content

Drawing sprite name in center of larger sprites.


Recoil

Recommended Posts

This is confusing.

Original code to draw text in the center of a 32x32 pixel sprite:

textX = ConvertMapX(Map(CurrentMap).Token(i).X * PicX) + (PicX / 2) - GetWidth((Trim$(Map(CurrentMap).Token(i).Name))) / 2

To simplify I have separated the variables.  I am using _spritesGfx(i).Size.X instead of PicX, because images can be either 32x32, or 64x64...they can even be larger, I just need the text in the center:

Dim spriteLocX As Integer = Map(CurrentMap).Token(i).X * PicX
Dim halfSpriteWidth As Integer = (_spritesGfx(i).Size.X / 2)
Dim fullSpriteWidth As Integer = (_spritesGfx(i).Size.X)
Dim tokenNameWidth As Integer = GetWidth((Trim$(Map(CurrentMap).Token(i).Name)))

This works only for 32x32 pixel sprites:

textX = (ConvertMapX(spriteLocX) + halfSpriteWidth) - (tokenNameWidth / 2)

This works only for 64x64 pixel sprites (I have not tried larger sprites but in theory it should work):

textX = (ConvertMapX(spriteLocX) + fullSpriteWidth) - (tokenNameWidth / 2)

Link to comment
Share on other sites

This is what it looks like using halfSpriteWidth.  I didn't notice it until I put a 96x96 token on there that the Y values are getting off as well:

95116ae29d3f418515183e359724b682.png

And this with fullSpriteWidth.  Apparently this does not work with 96x96:

fade0b546887c321310696bcbd5a87bf.png

This looks like it is not going to be as easy as I thought it would be, and the entire draw text sub will have to be reworked.  Let me know if uploading the whole source will work -_-

Link to comment
Share on other sites

Okay, Y axis was easy to solve:

textY = ConvertMapY(Map(CurrentMap).Token(i).Y * PicY) - 4

When I just set the X axis to the spriteLocX they ALL draw on the left side:

textX = (ConvertMapX(spriteLocX))

So this is half-solved...at least I know the _spritesGfx(i).Size.X is some weird amount that doesn't correlate to the actual width of the token.

Link to comment
Share on other sites

Omg, this is so jacked up  ???

Dim spriteLocX As Integer = Map(CurrentMap).Token(i).X * PicX
Dim halfSpriteWidth As Integer = (SpritesGfxInfo(Map(CurrentMap).Token(i).Sprite).Width / 2)
Dim tokenNameWidth As Integer = GetWidth((Trim$(Map(CurrentMap).Token(i).Name)))

textX = (ConvertMapX(spriteLocX)) + (halfSpriteWidth) - (tokenNameWidth / 2)

It works though.  I don't think anyone would have been able to help unless I posted my whole source -_-

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...