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