class GameScene: SKScene {
let balls = [
SKSpriteNode(imageNamed: "blueball.png"),
SKSpriteNode(imageNamed: "greenball.png"),
SKSpriteNode(imageNamed: "realredball.png"),
]
override func didMove(to view: SKView) {
spawnBalls()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for ball in balls{
ball.physicsBody = SKPhysicsBody()
ball.physicsBody?.affectedByGravity = true
}
}
func spawnBalls() {
for ball in balls{
balls[Int(arc4random_uniform(UInt32(balls.count)))]
ball.position = CGPoint(x: 0, y: 250)
ball.size = CGSize(width: 70, height: 70)
self.addChild(ball)
}
}
}
每次我的应用加载红球产生,但它应该随机产生红色,蓝色或绿色球。起初,它实际上工作,并会随机产生红色,绿色或蓝色,我不知道我是否意外改变了一些东西,但在最近两天它刚刚产生红色的那个。如果有人可以帮助那将是伟大的。感谢。
答案 0 :(得分:1)
你实际上并没有在spawnBalls中对随机球做任何事情。试试这个
Failed to load resource: the server responded with a status of 500 (Internal Server Error)