Hello Guest

Author Topic: Get position of actual sprite inside of original texture bounds  (Read 3501 times)

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
I have a game where you drag clothing items on a character (2D Game).  We designed the textures so that they all have the same texture size, but with the appropriate drawings/art within those bounds. We did this so we could drag a texture and the center will always be 0,0,0 so we never have to reposition the items within the game.

The problem I have is that when we move the texture to the position of the touch on the screen, this happens at the anchor point of the texture (in the center middle). If I change the anchor point to be the center of the actual item our 0,0,0 positioning system no longer works because the anchor is different on each item.

So my question is this: How do I get the WORLD POSITION of the actual sprite within the texture bounds so I can move the sprite object to the position of the touch?

See screenshot for example. I basically want to do this: tk2dSprite.transform.actualspriteposition = touch position

So the user would touch the screen and the crown in the image would move to the touch position (the actual crown image would be under the users finger). Then when they let go of the item I need only to move the sprite (the outside bounds) to 0,0,0 and it is aligned perfectly.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Get position of actual sprite inside of original texture bounds
« Reply #1 on: March 11, 2014, 01:36:36 pm »
GetBounds
vs
GetUntrimmedBounds

will give you the offset of where the actual bounds of the sprite is. GetBounds returns the bounds of the trimmed sprite - i.e. just the crown. GetUntrimmedBounds returns the full bounds of the sprite. You can work out the offsets you need to calculate world position from that.

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Get position of actual sprite inside of original texture bounds
« Reply #2 on: March 11, 2014, 05:21:05 pm »
Thanks!!!