首页 > 解决方案 > 我试图只允许 SKSpritenode 跳转一次但速度有问题

问题描述

我目前正在使用 WizardCharacter.physicsbody.velocity.dy,并检查它是否等于 0。我不希望角色能够在空中跳跃。我面临的问题是,我的角色正在休息,他没有移动,并且 y 的速度从 0 变为 1,同时没有对角色执行任何操作。我不确定为什么会这样,我正在使用 SpriteKit 和 SceneKit。我已经提供了我的代码,以及控制台正在打印的图片。

override func update(_ currentTime: TimeInterval) {
        print("\(String(describing: wizardCharacter.physicsBody?.velocity.dy))")
        cameraNode.position.x = wizardCharacter.position.x
        if wizardCharacter.action(forKey: "wizardRun") == nil {
            wizardCharacter.texture = SKTexture(imageNamed: "wizard_1_attack-b_001")
        }
if upArrow.contains(pointTouched)
            {
                if wizardCharacter.physicsBody?.velocity.dy == 0 && isJumping == true {
                upArrow.alpha = 0.5
                jumpWizard(forTheKey: "jumped")
                jumpWizardAnimation(fortheKey: "jumpedAnimation")
                }
            }

y 中的字符速度

标签: swiftsprite-kitscenekit

解决方案


推荐阅读