【问题标题】:Applying forces on an object [closed]对物体施加力[关闭]
【发布时间】:2014-08-17 22:35:15
【问题描述】:

如果我理解正确,当我“applyForce”时,只要应用 applyForce,它就会在我的矢量方向和力量上推动我的对象。 但是当我尝试在'touchesBegan'中对身体施加力时(因为我希望只要我触摸屏幕就让它向上推),我得到的只是一点点推动,让它跳跃几个像素然后它掉下来物理世界设置的结果。 (我还希望在“touchesEnded”时停止推动力) 想法有人吗? 谢谢

(Xcode 5,spriteKit)

【问题讨论】:

    标签: ios sprite-kit touchesbegan


    【解决方案1】:

    touchesBegan:只在屏幕被触摸时触发一次。

    要在您的手指触摸屏幕时继续执行某项操作,您可以执行以下操作:

    创建一个 BOOL ivar

    @implementation MyScene
    {
        BOOL theFingerTouches;
    }
    

    接下来按照您已经知道的方式注册触摸

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        theFingerTouches = true;
    }
    

    确保在触摸不再存在时也进行注册

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        theFingerTouches = false;
    }
    

    最后使用 update: 方法根据您的 BOOL 执行您需要的操作

    -(void)update:(CFTimeInterval)currentTime
    {
        if(theFingerTouches == true)
        {
            // some code here
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-20
      • 1970-01-01
      • 1970-01-01
      • 2018-12-05
      • 2017-06-13
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多