2012-10-11 65 views
1

我正在写一个游戏,当用户触摸屏幕左侧时,玩家向左移动,当他们触摸屏幕的右侧部分时,玩家向右移动。触摸并按住 - iPhone cocos2d

目前玩家只移动当你第一次触摸屏幕,我要被应用,只要用户拥有自己的手指在屏幕上的力量......我似乎无法找到一个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

不知道你是如何实现的举动,但对的touchesBegan,你可以开始在精灵一个CCMoveTo动作(屏幕边缘),并在ccTouchesEnded,你可以在精灵stopAllActions(或停止具体行动,如果你小心地处理它)。同样,许多方法来使用这个猫,这将非常依赖您正在实施的整体游戏逻辑和UI策略。

编辑:这是一种不依赖于CCActions

方式时:onTouchesBegan:

[self schedule:@selector(keepPushingFrank:) interval:.2]; // interval up to you, experiment 

时:onTouchesEnded或onTouchesCancelled

[self unchedule:@selector(keepPushingFrank:)] 

时: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). 

} 
+0

嘿伊夫 - 我使用的Box2D和应用内'handleFrankMove'冲动 – Chris