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中设置速度所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)