>我正在编写一个游戏,当用户触摸屏幕左侧时,玩家向左移动,当他们触摸屏幕的右侧时,玩家向右移动。
目前玩家只在你第一次触摸屏幕时移动,我希望只要用户将手指放在屏幕上,就会施加力......我似乎找不到为此的 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];
}
不知道你是如何实现移动的,但是在触摸开始时,你可以在精灵上启动一个CCMoveTo动作(屏幕的边缘),而在ccTouchesEnded上,你可以在精灵上停止AllActions(或者如果你小心翼翼地保持手柄,就停止特定动作)。同样,使用哪种猫皮肤的许多方法将在很大程度上取决于您正在实施的整体游戏逻辑和 UI 策略。
编辑:这是一种不依赖CCActions的方法
什么时候: 开始接触开始:
[self schedule:@selector(keepPushingFrank:) interval:.2]; // interval up to you, experiment
时间:触摸结束或取消
[self unchedule:@selector(keepPushingFrank:)]
什么时候: 触摸移动:
[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).
}