检查SCNNode SCNAction是否完成 [英] Check if SCNNode SCNAction is finished

查看:44
本文介绍了检查SCNNode SCNAction是否完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个SceneKit 3D迷宫世界,玩家可以在其中移动.诸如跳跃之类的一些动作涉及在几秒钟的时间内上下移动相机,同时更改为观看方向.在这段时间里,我想忽略用户的轻击和滑动,这些轻击和轻击通常会导致其他类型的运动,例如转身和前进.

I have created a SceneKit 3D maze world in which a player can move. Some of the moves like jumping involve moving the camera up and down while changing to view direction over a period of time of several seconds. During this time I would like to ignore taps and swipes by the user that would normally result in other types of movements like turning and moving forward.

我可以创建一个与跳转持续时间匹配的计时器,并设置一个布尔值,但是我希望找到一种更简单的方法来检查摄像机的SCNNode.

I could create a timer that matches the jump duration and sets a Bool but I was hoping for a simplier way of checking the SCNNode for the camera.

是否有一种简单的方法来查看摄像机的SCNNode是否不再运行SCNAction进行跳转,因此我可以在其他点击和滑动动作之前添加此逻辑?

Is there a simple way to see if the SCNNode for the camera is no longer running the SCNAction for the jump so I can add this logic in front of other tap and swipe actions?

或者也许有一个SCNAction可以设置我可以在跳转序列的开头和结尾处放置的Bool?

Or perhaps there is an SCNAction that could set the Bool that I could put at the start and finish of my jump sequence?

这是我的跳转代码:

        let jumpUp: SCNAction = SCNAction.move(to: SCNVector3Make(Float(Int(-yPos)), Float(Int(xPos)), jumpHeight), duration: jumpTime)
        let jumpAppex: SCNAction = SCNAction.wait(duration: jumpWaitTime)
        let fallDown: SCNAction = SCNAction.move(to: SCNVector3Make(Float(Int(-yPos)), Float(Int(xPos)), cameraHeight), duration: jumpTime)

        var lookDown: SCNAction = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(π), duration: jumpTurnTime)
        let noLook: SCNAction = SCNAction.wait(duration: jumpTime*2.0)
        var lookBack: SCNAction = SCNAction.rotateTo(x: 0, y: 0, z: 0, duration: jumpTurnTime)

        switch playerDirection.direction
        {
            case .south:
                lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(southZ), duration: jumpTurnTime)
                lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(southZ), duration: jumpTurnTime)
            case .north:
                lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(northZ), duration: jumpTurnTime)
                lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(northZ), duration: jumpTurnTime)
            case .east:
                lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(eastZ), duration: jumpTurnTime)
                lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(eastZ), duration: jumpTurnTime)
            case .west:
                lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(westZ), duration: jumpTurnTime)
                lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(westZ), duration: jumpTurnTime)
        }

        let sequenceJump = SCNAction.sequence([jumpUp, jumpAppex, fallDown])
        let sequenceLook = SCNAction.sequence([lookDown, noLook, lookBack])

        mazeScene.mazeCamera.runAction(sequenceJump)
        mazeScene.mazeCamera.runAction(sequenceLook)

谢谢

格雷格

推荐答案

我最终使用了.customAction:

I ended up using a .customAction:

我添加了一个类变量isJumping

I added a class variable isJumping

然后在我添加的功能代码的前面:

then at front of the function code I added:

 isJumping = true

并添加了SCNAction:

and added the SCNAction:

 let jumpDone: SCNAction = SCNAction.customAction(duration: 0, action: {_,_ in self.isJumping = false})

然后将顺序更改为:

 let sequenceLook = SCNAction.sequence([lookDown, noLook, lookBack, jumpDone])

然后我只是在isJumping上执行if来查看跳跃动作是否已完成.

then I just do an if on isJumping to see if the jump movement has completed.

这篇关于检查SCNNode SCNAction是否完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆