spritekitで初歩的な簡単なゲームの作成中です。
8つのノードを作成し、それぞれがバラバラのタイミングで動き出してほしいのですが、なかなかうまくいきません。
この8つのノードがランダムにバラバラのタイミングで動き出すためにはどのような修正を加えればよいでしょうか?ご回答のほう、よろしくお願いします。
class GameScene: SKScene {
private var moveToAction :SKAction!
// 衝突に使うBitMask.
let msCategory: UInt32 = 0x1 << 0
let ckCategory: UInt32 = 0x1 << 1
override func didMoveToView(view: SKView) {
// 画像からスプライトを作成する
let mySprite = SKSpriteNode(imageNamed: "kuri_2.png")
// サイズプロパティでサイズを設定
mySprite.size = CGSize(width: 100, height: 100)
// ポジションプロパティで設定
// 画像の描画場所を指定.
mySprite.position = CGPoint(x: 500, y: 100)
addChild(mySprite)
// ノード8つをつくります
let mySprite2 = SKSpriteNode(imageNamed: "kuri_2.png")
mySprite2.size = CGSize(width: 100, height: 100)
mySprite2.position = CGPoint(x: 0, y: 500)
addChild(mySprite2)
let mySprite3 = SKSpriteNode(imageNamed: "kuri_2.png")
mySprite3.size = CGSize(width: 100, height: 100)
mySprite3.position = CGPoint(x: 0, y: 0)
addChild(mySprite3)
let mySprite4 = SKSpriteNode(imageNamed: "kuri_2.png")
mySprite4.size = CGSize(width: 100, height: 100)
mySprite4.position = CGPoint(x: 1000, y: 1000)
addChild(mySprite4)
let mySprite5 = SKSpriteNode(imageNamed: "kuri_2.png")
mySprite5.size = CGSize(width: 100, height: 100)
mySprite5.position = CGPoint(x: 500, y: 1000)
addChild(mySprite5)
let mySprite6 = SKSpriteNode(imageNamed: "kuri_2.png")
mySprite6.size = CGSize(width: 100, height: 100)
mySprite6.position = CGPoint(x: 0, y: 1000)
addChild(mySprite6)
let mySprite7 = SKSpriteNode(imageNamed: "kuri_2.png")
mySprite7.size = CGSize(width: 100, height: 100)
mySprite7.position = CGPoint(x: 1000, y: 500)
addChild(mySprite7)
let mySprite8 = SKSpriteNode(imageNamed: "kuri_2.png")
mySprite8.size = CGSize(width: 100, height: 100)
mySprite8.position = CGPoint(x: 1000, y: 0)
addChild(mySprite8)
// 回転の動きをいれる
let action1 = SKAction.rotateByAngle(CGFloat(360 * M_PI / 180), duration: 1)
let action3 = SKAction.repeatActionForever(action1)
// 指定した位置まで移動させる
let action4 = SKAction.moveTo(CGPoint(x: 512, y: 380), duration: 1)
// 複数の動きを同時に処理
let actionx = SKAction.group([action1,action3,action4])
// それぞれの出現時間を変えたい
let action2y = SKAction.waitForDuration(3.0,withRange: 3.0)
let action2x = SKAction.group([actionx,action2y])
let action3y = SKAction.waitForDuration(1.0,withRange: 2.0)
let action3x = SKAction.group([actionx,action3y])
let action4y = SKAction.waitForDuration(5.0,withRange: 3.0)
let action4x = SKAction.group([actionx,action4y])
let action5y = SKAction.waitForDuration(10.0,withRange: 2.0)
let action5x = SKAction.group([actionx,action5y])
let action6y = SKAction.waitForDuration(3.0,withRange: 2.0)
let action6x = SKAction.group([actionx,action6y])
let action7y = SKAction.waitForDuration(4.0,withRange: 2.0)
let action7x = SKAction.group([actionx,action7y])
let action8y = SKAction.waitForDuration(5.0,withRange: 2.0)
let action8x = SKAction.group([actionx,action8y])
// 実行します
mySprite.runAction(actionx)
mySprite2.runAction(action2x)
mySprite3.runAction(action3x)
mySprite4.runAction(action4x)
mySprite5.runAction(action5x)
mySprite6.runAction(action6x)
mySprite7.runAction(action7x)
mySprite8.runAction(action8x)