画面にタッチすると体を動かし続け、タッチを離すと停止します。私は 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)]];
}
間違っている場合は、ロジックとコードを書いてください。助けてください。
ありがとう