Sprite position in physics body

I’m creating my character by subclassing sprite and adding a physics body. Because of my animation frames, the sprite size is a little bigger than I would like and I would like to be able to position my sprite differently inside my physics body but setAnchorPoint seems to do nothing at all. Is there any way to achieve this? I saw some other threads that seemed to have no resolution. Has anything changed?

Your PhysicsBody should not be any bigger, I would think. Can you turn on your debug borders and post some screenshots?

Sorry I don’t think I explained myself very well. My idle animation is such that the character sort of moves up and down. The size of the physics body seems to represent his tallest height. I’m using sprite->getContentSize() to get the Size object that I’m using for the physics body. the problem is that I would like to reposition the origin of the sprite so that it is in the average middle for all animation frames.

can you provide code that I can drop into a sample project and see?

After looking through this, I think it’s an issue with TexturePacker. I appreciate you trying to help me out but I either need to get my texture packer settings correct or figure out how to trim transparent pixels.

E-mail Code and Web for help. @AndreasLoew is a member here.

What’s happening here depends a bit on your settings TexturePacker.

TexturePacker comes with a built-in anchor point editor. To use it you have to use the cocos2d-x exporter.

There’s “Enable pivot points” in the right sidebar. If this is enabled the anchor points are overwritten with the values from the plist file.

So you should be able to either use the editor to set the anchors - or disable it in TexturePacker.

1 Like

Thanks a lot! That’s actually exactly what I was looking for.