swift - 我试图只允许 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")
}
}
解决方案
推荐阅读
- python - 如何返回满足条件的字典中的最后一个值
- ldap - WSO2am 与 ldap AD 集成时抛出“尝试连接到端点时出错。无法为 ssl://localhost:7712 借用客户端”
- wso2 - 如果请求正文中不存在属性,有没有办法为属性中介设置默认值?
- python - 如何以python方式将numpy.array传递给numpy.array中的对象方法
- react-native - 错误:无法解析模块“react-native-gesture-handler”
- php - 如何使用谷歌广告词 API 的 php 客户端库创建产品组(产品分区)?
- maatwebsite-excel - 如何修复 Laravel Excel 中不允许“MongoDB\Driver\Manager”的序列化
- jquery - Ajax GET 请求响应缺少数据字段
- java - 如何在 Java 中创建一个简单的连接表?
- powershell - 响应码不等于 200 时获取 HTTP 响应码