Cocos2d-iPhone with Box2D: CCPhysicsSprite EXC_BAD_ACCESS

断了今生、忘了曾经 提交于 2019-12-08 21:40:33

With CCPhysicsSprite you must set the body BEFORE you set the position of the sprite. I assume that this line is where the crash occurs:

sprite.position = point;

If you look at CCPhysicsSprite it overrides the position/setPosition to always use the values from the contained b2body object. So it really accesses its b2body property, which is nil at that point → Crash. Generally after creating a CCPhysicsSprite you want to set its .b2body as soon as possible - there might be more occasions where similar problems might occur just because you need to set the .b2body property first.

So, move sprite.position = point; below sprite.b2Body = body;.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!