我在gamescene.sks
创建了8个拨片。我知道如何手动控制它们,但在这种情况下,我希望它们都能在按下按钮时自动开始在各自的“通道”中来回摆动(意味着它们不会相互碰撞)(我没有创建按钮,因为如果之前应该是idk或者paddles正常运行)。
我不是要求代码,但我只需要大致了解我需要实现的命令,以便在按下按钮时线性地来回移动单个拨片(随机定位)。我相信我可以从那里找到其他所有东西。
提前致谢!!!
按下START按钮→8个拨片(随机放置在各自的通道中)开始来回摆动(彼此不同步)
import SpriteKit
import GameplayKit
class GameScene: SKScene {
var squareRight = SKSpriteNode()
var squareLeft = SKSpriteNode()
var paddleL1 = SKSpriteNode()
var paddleL2 = SKSpriteNode()
var paddleL3 = SKSpriteNode()
var paddleL4 = SKSpriteNode()
var paddleR1 = SKSpriteNode()
var paddleR2 = SKSpriteNode()
var paddleR3 = SKSpriteNode()
var paddleR4 = SKSpriteNode()
override func didMove(to view: SKView) {
squareRight = self.childNode(withName: "squareRight") as! SKSpriteNode
squareLeft = self.childNode(withName: "squareLeft") as! SKSpriteNode
paddleL1 = self.childNode(withName: "paddleL1") as! SKSpriteNode
paddleL2 = self.childNode(withName: "paddleL2") as! SKSpriteNode
paddleL3 = self.childNode(withName: "paddleL3") as! SKSpriteNode
paddleL4 = self.childNode(withName: "paddleL4") as! SKSpriteNode
paddleR1 = self.childNode(withName: "paddleR1") as! SKSpriteNode
paddleR2 = self.childNode(withName: "paddleR2") as! SKSpriteNode
paddleR3 = self.childNode(withName: "paddleR3") as! SKSpriteNode
paddleR4 = self.childNode(withName: "paddleR4") as! SKSpriteNode
}
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
}
}
答案 0 :(得分:1)
作为一套通用指南,我会:
PaddleDirection
枚举,
movingRight和movingLeft PaddleNode
var currentDirection = PaddleDirection.stationary
添加到您的PaddleNode。update()
枚举所有拨片并调整他们的
根据他们是向左还是向右移动来定位。