當我觸摸屏幕時我想移動身體,當我釋放觸摸時停止。 我使用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)]];
}
因此,如果其錯誤比請告訴我寫的邏輯和代碼 請幫助我。
謝謝
它的工作原理,但當我觸摸屏幕它移動後釋放它停止,但在下次點擊屏幕後它不起作用 – 2012-08-25 06:56:43