我可以製作一個隨機選擇並從屏幕頂部到底部的SK節點數組。例如,假設我有25個左右不同的平臺,這些平臺將會在肖像iPhone上掉下來。我需要它從數組中隨機選擇一個平臺開始,然後在一定時間/或像素空間之後隨機選擇另一個以繼續相同的動作,直到達到底部等等。Im新到快速但有相當體面的瞭解它。我還沒有找到如何創建一個SKsprite節點數組。有人可以幫忙嗎?快速移動多個精靈節點
到目前爲止,我已經能夠獲得任何類似於我想要的效果的唯一方法是將每個節點放在屏幕上並將它們添加到字典中,並使它們像這樣移動
類ObstacleStatus {
var isMoving = false
var timeGapForNextRun = Int(0)
var currentInterval = Int(0)
init(isMoving: Bool, timeGapForNextRun: Int, currentInterval: Int) {
self.isMoving = isMoving
self.timeGapForNextRun = timeGapForNextRun
self.currentInterval = currentInterval
}
func shouldRunBlock() -> Bool {
return self.currentInterval > self.timeGapForNextRun
}
和
func moveBlocks(){
for(blocks, ObstacleStatus) in self.blockStatuses {
var thisBlock = self.childNodeWithName(blocks)
var thisBlock2 = self.childNodeWithName(blocks)
if ObstacleStatus.shouldRunBlock() {
ObstacleStatus.timeGapForNextRun = randomNum()
ObstacleStatus.currentInterval = 0
ObstacleStatus.isMoving = true
}
if ObstacleStatus.isMoving {
if thisBlock?.position.y > blockMaxY{
thisBlock?.position.y -= CGFloat(self.fallSpeed)
}else{
thisBlock?.position.y = self.origBlockPosistionY
ObstacleStatus.isMoving = false
}
}else{
ObstacleStatus.currentInterval++
}
}
}
使用該用於該隨機函數
func randomNum() -> Int{
return randomInt(50, max: 300)
}
func randomInt(min: Int, max:Int) -> Int {
return min + Int(arc4random_uniform(UInt32(max - min + 1)))
}
這一切對我來說都是以隨機的時間間隔往下移動,但是增加隨機數的最小或最大值並不會影響間隙的實際時間。我需要能夠指定距離或時間差距。
您應該添加您迄今嘗試的內容。 – 2014-09-28 07:51:33
增加了我用過的一些東西。 – Alex 2014-09-28 08:45:42