import SpriteKit
import GameplayKit
class GameScene: SKScene {
var player = SKShapeNode()
let ballRadius: CGFloat = 20
override func didMove(to view: SKView) {
view.scene?.anchorPoint = CGPoint(x: 0.5,y : 0.5)
player = SKShapeNode(circleOfRadius: ballRadius)
player.name = "player"
player.fillColor = .green
player.position = CGPoint(x: 0, y: 0)
player.physicsBody?.isDynamic = true
self.addChild(player)
player.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 10))
}
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
}
}
我试图给玩家增添一种冲动,但我无法弄明白,请特别注意我是初学者。我认为这与skshapenode不是基于体积的对象有关,但我不确定
答案 0 :(得分:0)
你走在正确的轨道上!您需要做的就是为您的播放器添加一个物理主体以使其移动。
player.physicsBody = SKPhysicsBody(circleOfRadius: 30)
// the 30 in this case is an example. You can just change it to whatever you want