gpt4 book ai didi

ios - 对 SKShapeNode 施加脉冲

转载 作者:行者123 更新时间:2023-11-30 12:27:30 26 4
gpt4 key购买 nike

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 不是基于体积的对象有关,但我不确定

最佳答案

你走在正确的道路上!您所需要做的就是向您的播放器添加一个物理体以使其移动。

player.physicsBody = SKPhysicsBody(circleOfRadius: 30) 
// the 30 in this case is an example. You can just change it to whatever you want

关于ios - 对 SKShapeNode 施加脉冲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43988171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com