简体   繁体   中英

Sprite Kit How to change physics body programatically

How can I change a sprite's physics body programatically? Here's what I'm doing:

[mySprite removeFromParent];
mySprite.physicsBody = [MySprite body2];
// body setup
[myContainer addChild: mySprite];

But somehow it just doesn't work. What am I doing wrong?

EDIT: Here's my hero character, he's composed of 3 bodies

  1. feet - larger circle as a feet sensor
  2. polygon - the one I want to flip horizontally
  3. smaller circle - it is there pinned to the polygon so that the textures follow the other bodies

在此处输入图片说明

You can mirror the sprite like this :

mySprite.xScale = -1; // assuming the scale desired is indeed 1.

I believe that you can do the same with a SKShapeNode, so you can do the same with your physics body.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM