Recoil Posted April 18, 2016 Share Posted April 18, 2016 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 More sharing options...
Recoil Posted April 18, 2016 Author Share Posted April 18, 2016 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: And this with fullSpriteWidth. Apparently this does not work with 96x96: 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 More sharing options...
Recoil Posted April 18, 2016 Author Share Posted April 18, 2016 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 More sharing options...
Recoil Posted April 18, 2016 Author Share Posted April 18, 2016 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 More sharing options...
Kibbelz Posted April 19, 2016 Share Posted April 19, 2016 Assuming x and y start at 0,0 of the text and top left of the image it should simply be (starting position) + (image width/2) - (Text width/2) EDIT: Just realised tou solved the answer yourself LOL Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now