将花栗鼠身体移动到精灵位置
我有一个花栗鼠的形状,有一个身体,在一个空间里。我正在将身体从空间中移开,以便我可以定位它并且不会使其因重力等而掉落。我需要能够使这个身体移动,所以我不会使其静止。
我需要主体根据场景中 Cocos2D 精灵的位置 + 偏移量来更新其位置。
我设置身体位置:
collShape->body->p = collSprite.position; - 这似乎不起作用,不是编译错误,它运行,但碰撞形状不移动。
是否可以根据我的勾选方法中精灵的位置来移动碰撞体?
I have a Chipmunk shape, with a body, in a space. I am removing the body from the space so that I can position it and not have it fall due to gravity etc. I need to be able to make this body move, so I am not making it static.
I need the body to update it's position according to the position of a Cocos2D sprite in the scene + an offset.
I'm setting the bodies position with:
collShape->body->p = collSprite.position; - this seems to not work, not compile errors, it runs, but the collision shape doesn't move.
Is it possible to move a collision body based upon the position of a sprite in my tick method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你正在做的事情应该是可能的。
最简洁的方法是创建一个从 CCSprite 派生的新类,然后重写 setPosition 方法来更新精灵的主体。
这样做的优点是,只要精灵的位置发生变化(无论是由您或任何动画序列明确更改),花栗鼠的身体都会自动更新。
What you're doing should be possible.
Cleanest way is to create a new class that derives from CCSprite and then override the setPosition method to update the sprite's body.
The advantage of this, is that anytime the sprite's position is changed (either explicitly by you or by any animation sequence) the Chipmunk body will automatically get updated.
当您调用 cpSpaceStep 时,将创建活动形状列表,并为每个形状调用 cpShapeUpdateFunc。该函数如下所示:
...它将形状更新为它所附加的身体位置和旋转。如果这种情况没有发生,也许您的形状尚未添加到空间或尚未添加到主体?
When you call cpSpaceStep, a list of active shapes is created and cpShapeUpdateFunc is called for each. That function looks like:
...which updates the shape to the body location and rotation it's attached to. If that's not happening maybe your shape has not been added to the space or has not been added to the body?