我是SpriteKit的新手,我不知道为什么我的代码根本不起作用。在我创建所有节点之后,我想要的唯一受物理影响的是球。我想对球节点施加冲动,但我可以“让它起作用。”
以下是代码:
import SpriteKit
import GameplayKit
class GameScene: SKScene {
var ramp = SKSpriteNode()
var label = SKLabelNode()
var ball = SKSpriteNode()
override func didMove(to view: SKView) {
ball = self.childNode(withName: "ball") as! SKSpriteNode
ramp = self.childNode(withName: "ramp") as! SKSpriteNode
label = self.childNode(withName: "label") as! SKLabelNode
ball.physicsBody?.isDynamic = true
ball.physicsBody?.affectedByGravity = true
let border = SKPhysicsBody(edgeLoopFrom: self.frame)
border.friction = 0
border.restitution = 0
self.physicsBody = border
ball.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 50))
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
}
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
}
}