【问题标题】:Touch and hold - iPhone cocos2d长按 - iPhone cocos2d
【发布时间】:2012-10-11 21:05:54
【问题描述】:

我正在编写一个游戏,当用户触摸屏幕的左侧时,玩家会向左移动,当他们触摸屏幕的右手部分时,玩家会向右移动。

目前播放器仅在您第一次触摸屏幕时移动,我希望只要用户将手指放在屏幕上就可以施加力...我似乎找不到为此的 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];
}

【问题讨论】:

    标签: iphone objective-c cocos2d-iphone touch


    【解决方案1】:

    不知道你是如何实现移动的,但是在 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).
    
    }
    

    【讨论】:

    • 嘿 Yves - 我正在使用 Box2d 并在 handleFrankMove 中应用冲动
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-09
    • 1970-01-01
    相关资源
    最近更新 更多