大家好,我是新的COCOS2DX框架,并试图开发砖破碎机游戏。我正在关注此演示Brick breker game本教程位于cocos2d(iPhone)中。我在cocos2dx中编写代码并正确工作。但是当我实施ccTouchesMoved
的方法。我的代码编译和运行正常,但随着我触摸(单击)屏幕下来,并给错误违反ocures。我的代码是ccTouchesMoved在cocos2dx
void HelloWorld::ccTouchesMoved(CCSet* touches, CCEvent* event)
{
if (_mouseJoint == NULL) return;
CCTouch *myTouch = (CCTouch*)touches->anyObject();
CCPoint location = myTouch->locationInView();
location = CCDirector::sharedDirector()->convertToGL(location);
b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
_mouseJoint->SetTarget(locationWorld);
}
我该如何解决此问题。请指导我。
在您提供的演示
您的代码不检查空指针。也许touch是null,也许myTouch是,或者CCDirector :: sharedDirector()返回NULL。 –
哪条线突破? _mouseJoint-> setTarget? –
是的,它打破了同一条线。 –