Random number from an array without repeating the same number twice in a row?

前端 未结 4 1456
慢半拍i
慢半拍i 2020-12-22 10:32

I am making a game using Swift and SpriteKit where i move an object to random locations based on an array.

The array that is made up of CGPoints:

let         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-22 11:03

    I think Larme's suggestion is pretty clever, actually.

    easyArray.append(easyArray.removeAtIndex(Int(arc4random_uniform(UInt32(easyArray.count)-1))))
    selector.runAction(SKAction.moveTo(easyArray.last!, duration: 0))
    

提交回复
热议问题