gpt4 book ai didi

swift - 如何在 Swift 中设置速度

转载 作者:搜寻专家 更新时间:2023-10-31 22:03:41 25 4
gpt4 key购买 nike

下面是 Sprite Kit 中的 Enemy 节点,在 Swift 中。我已经为节点设置了速度,但是当它产生时没有运动。 Xcode 没有给我任何错误,是不是我做错了什么?

class Enemy: SKSpriteNode {

init(imageNamed: String) {

let imageTexture = SKTexture(imageNamed: imageNamed)
super.init(texture: imageTexture, color: nil, size: imageTexture.size())

self.name = "Enemy"

self.physicsBody = SKPhysicsBody(rectangleOfSize: imageTexture.size())
self.physicsBody?.dynamic = false
self.physicsBody?.velocity = CGVectorMake(10.0,10.0)

}
}

最佳答案

来自 Apple 的 SpriteKit documentation :

A Boolean value that indicates whether the physics body is moved by the physics simulation.

Declaration

Swift

var dynamic: Bool

Objective-C

@property(nonatomic, getter=isDynamic) BOOL dynamic

Discussion

If the value is NO, the physics body ignores all forces and impulses applied to it. This property is ignored on edge-based bodies; they are automatically static.

正如 0x141E 所说,你必须让你的 SKPhysicsBody 动态,否则它不会移动。

关于swift - 如何在 Swift 中设置速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27084076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com