如果这个问题已经被提问/回答,我提前道歉,我不知道怎么说标题,更不用说搜索了。
我正在制作这款iOS游戏,你必须点击该游戏,然后点击下面的支柱。我试图实施“坏支柱”#34 ;;支柱,如果触及,将导致游戏结束。理想情况下,我喜欢用坏柱子来代替好柱子,但它们会在它们之上或旁边产卵。目前我有一个很好的支柱,设置在SKAction阵列的计时器上。
忽略我的代码中的任何评论,他们需要更新
添加支柱功能:
func addPillar(){
let max = Double(UInt32.max)
let randomInterval = ((Double(arc4random()) / max)+0.4) * 0.5
// initiallize pillarArray as a shuffled array
pillarArray = GKRandomSource.sharedRandom().arrayByShufflingObjects(in: pillarArray) as! [String]
// initiallize pillar node to first item in shuffled pillarArray
pillar = SKSpriteNode(imageNamed: pillarArray[0])
// set pillar position as a random integer between lowestValue , highestValue
let pillarPosition = GKRandomDistribution(lowestValue: Int(-self.frame.height / 2) , highestValue: Int((-self.frame.height / 2) + 40 ))
let position = CGFloat(pillarPosition.nextInt())
pillar.position = CGPoint(x: self.frame.width - 10, y: (position));
// set pillar physics body
pillar.physicsBody = SKPhysicsBody(rectangleOf: pillar.size)
pillar.physicsBody?.isDynamic = false;
pillar.physicsBody?.categoryBitMask = pillarBitMask
pillar.physicsBody?.collisionBitMask = playerBitMask
pillar.physicsBody?.contactTestBitMask = playerBitMask
//pillar.physicsBody?.restitution = 0.80
pillar.physicsBody?.friction = 10
// add a new pillar node to the scene
if(!isPaused){
self.addChild(pillar)
}
// an array of type SKAction
var animArray = [SKAction]()
// append a move sequence to the array for "time" seconds.
if(timerIsRunning && isPaused == true){
animArray.append(SKAction.stop())
}
animArray.append(SKAction.wait(forDuration: TimeInterval(Double(randomInterval))))
animArray.append(SKAction.move(to: CGPoint(x: -self.frame.size.width + 5, y: pillar.position.y), duration: 4))
// run the sequence
animArray.append(SKAction.removeFromParent())
pillar.run(SKAction.sequence(animArray))
计时器控制何时产生支柱:
pausedTimer = Timer.scheduledTimer(timeInterval: TimeInterval(1), target: self, selector: #selector (pauseTimer), userInfo: nil, repeats: true)
至于糟糕的支柱,它的设置方式与常规支柱相同,即支柱功能,阵列和计时器,但我一直试图摆弄时机,但我可以&#39 ;似乎让它以我想要的方式运作。
SKAction数组中是否有任何方法,或者只是一般的方法,可以让我选择在不必创建另一个数组/定时器/函数的情况下生成的内容?
请告诉我,我需要提供其他代码或提供说明。感谢