当我触摸屏幕时我想连续移动我的身体,当我释放触摸时停止。我正在使用 box2d 和 cocos2d,我真的不知道为什么我的代码不能很好地执行。我使用 touchesBegan 进行精灵身体运动
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
ccTime dt;
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
location=[[CCDirector sharedDirector]convertToGL:location];
[self moveRight:dt];
// [self doWhateverYouWantToDo];
// [self doItWithATouch:touch];
}
-(void)moveRight:(ccTime)dt
{
CCSprite *ballright=(CCSprite *)ballbody->GetUserData();
NSLog(@"Ball PositionX: %f",ballbody->GetPosition().x);
NSLog(@"Ball PositionY: %f",ballbody->GetPosition().y);
[ballright runAction:[CCMoveTo actionWithDuration:1 position:ccp(ballbody->GetPosition().x,ballbody->GetPosition().y+5*dt)]];
}
所以如果它错了,请告诉我写逻辑和代码请帮助我。
谢谢