当我触摸屏幕时我想移动身体,当我释放触摸时停止。 我使用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