gpt4 book ai didi

ios - .applyimpulse 不适用于 Xcode 8.3.3 中的 SKSpriteNode()

转载 作者:行者123 更新时间:2023-11-29 11:43:11 24 4
gpt4 key购买 nike

我一直在尝试遵循 YouTube 上的 Pong 指南(我是 SpriteKit 的新手),当我在 Xcode 8.3.3 中运行我的代码时,球没有移动。该指南使用 Xcode 8,因此一定有所改变。这是我的 GameScene.swift 代码:

import SpriteKit
import GameplayKit

class GameScene: SKScene {

var Ball = SKSpriteNode()
var comPaddle = SKSpriteNode()
var mainPaddle = SKSpriteNode()

override func didMove(to view: SKView) {

Ball = self.childNode(withName: "Ball") as! SKSpriteNode
mainPaddle = self.childNode(withName: "mainPaddle") as! SKSpriteNode
comPaddle = self.childNode(withName: "comPaddle") as! SKSpriteNode

Ball.physicsBody?.isDynamic = true;
Ball.physicsBody?.applyImpulse(CGVector(dx: 20, dy: 20))


let border = SKPhysicsBody(edgeLoopFrom: self.frame)

border.friction = 0
border.restitution = 1

self.physicsBody = border
}


override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
}
}

最佳答案

正如 Simone Pistecchia 所指出的,我没有创建物理体。我使用以下命令执行此操作:

Ball.physicsBody = SKPhysicsBody(circleOfRadius: Ball.size.width)

关于ios - .applyimpulse 不适用于 Xcode 8.3.3 中的 SKSpriteNode(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45328285/

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