我正在写一个游戏,当用户触摸屏幕的左侧时,玩家向左移动,当他们触摸屏幕的右手部分时,玩家向右移动。
目前播放器仅在您第一次触摸屏幕时移动,我希望只要用户将手指放在屏幕上就可以应用该力...我似乎无法为此找到API调用。我该怎么办?
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self handleFrankMove:touches withEvent:event];
}
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[self handleFrankMove:touches withEvent:event];
}
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self handleFrankMove:touches withEvent:event];
}
答案 0 :(得分:0)
不知道你是如何实现移动的,但是在touchesBegan上,你可以在sprite上启动CCMoveTo动作(屏幕边缘),而在ccTouchesEnded上,你可以在精灵上停止所有动作(或者如果你停止特定动作)小心翼翼地保持它的手柄)。再一次,许多使用它的猫皮肤的方法在很大程度上取决于你正在实施的整体游戏逻辑和UI策略。
编辑:这是一种不依赖于CCActions的方式
when:onTouchesBegan:
[self schedule:@selector(keepPushingFrank:) interval:.2]; // interval up to you, experiment
when:onTouchesEnded或onTouchesCancelled
[self unchedule:@selector(keepPushingFrank:)]
when:onTouchesMoved:
[self computeFingerLogicforTouch:_frankTouch]; // you may need this to control
// behaviour in keepPushingFrank
并添加如下方法:
-(void) keepPushingFrank:(ccTime) dt{
// do your thing with box2D to change forces
// on Frank. you may want to setup some iVars
// to compute 'finger intention' when it moves
// and apply physics accordingly (dont know your
// app).
}