1

I am trying to make a game about balls and using sprite kit with physics body for IOS 7. My problem is about resting objects when contact / collide. Here is my code in didBeginContact:

[contact.bodyA setVelocity:CGVectorMake(0, 0)];
[contact.bodyB setVelocity:CGVectorMake(0, 0)];
contact.bodyA.resting = YES;
contact.bodyB.resting = YES;

Actually contact.bodyA is already resting but I just set it to make sure both objects are set to resting. The problem is, balls are not touching to each other even if I set contact.bodyA(or B).resting = YES.

This is what I want:

http://i.stack.imgur.com/p8JTk.png

This is what happening sometimes:

http://i.stack.imgur.com/LWORO.png

As you can see in second picture, the blue ball is a bit far from other balls. Is there any other way to magnet the ball at contact point always?

4

1 回答 1

0

这可能是物理体的问题。我假设你正在使用[SKPhysicsBody bodyWithCircleOfRadius:spriteWidth/2]. 你确定你的精灵图像是正确的大小并且与你喂给物理体构造函数的半径相匹配吗?

也许您可以将对象的位置存储在属性prevPosition中,当检测到碰撞时,返回精灵节点的位置prevPosition并将主体设置为resting?
`

于 2013-12-11T01:52:28.313 回答