1
我正在嘗試將一個精靈從左到右移動到屏幕上。我聽說我可以通過使用velocity屬性來做到這一點,或者其他方式也可以,但這裏是我的代碼。在Sprite工具包中的屏幕上移動精靈
import SpriteKit
class GameScene: SKScene, SKPhysicsContactDelegate {
let redBall = SKSpriteNode(imageNamed: "redball")
override func didMoveToView(view: SKView) {
let thrust = CGFloat(0.12)
let thrustDirection = Float()
//RedBall Properties
redBall.physicsBody = SKPhysicsBody(circleOfRadius: redBall.size.width/2)
redBall.physicsBody?.velocity
addChild(redBall)
//World Phyisics Properties
let worldBorder = SKPhysicsBody(edgeLoopFromRect: self.frame)
self.physicsBody?.friction = 1
self.physicsBody = worldBorder
self.physicsWorld.gravity = CGVectorMake(0, 0)
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
}
}
謝謝!
我怎麼會移回向左嗎? –
我更新了我的答案 – TheCodeComposer