我試圖將5幀的動畫合併到我現有的spritenode的spawn函數中。目前,烏鴉從右向左移動穿過屏幕,但我想製作這個動畫,無論我嘗試什麼,我都會產生線程1錯誤。帶有產卵功能的動畫圖像
通過註釋掉某些代碼,我可以在屏幕上的靜態位置對鳥進行動畫處理,或者將鳥從右向左但不動畫(註釋出spawn func)。
我知道下面的代碼不會在當前窗體中工作,但它是我正在處理的一切,希望有人能幫助我。
下面是我的代碼我想起來插槽...
謝謝
//did move to view
var crowTexture1 = SKTexture(imageNamed: "crow1")
crowTexture1.filteringMode = SKTextureFilteringMode.Nearest
var crowTexture2 = SKTexture(imageNamed: "crow2")
crowTexture2.filteringMode = SKTextureFilteringMode.Nearest
var crowTexture3 = SKTexture(imageNamed: "crow3")
crowTexture3.filteringMode = SKTextureFilteringMode.Nearest
var crowTexture4 = SKTexture(imageNamed: "crow4")
crowTexture4.filteringMode = SKTextureFilteringMode.Nearest
var crowTexture5 = SKTexture(imageNamed: "crow5")
crowTexture5.filteringMode = SKTextureFilteringMode.Nearest
var animFly = SKAction.animateWithTextures([crowTexture1, crowTexture2, crowTexture3, crowTexture4, crowTexture5], timePerFrame: 0.1)
var fly = SKAction.repeatActionForever(animFly)
var distanceToMoveBird = CGFloat(self.frame.size.width + 2 * crowTexture1.size().width);
var moveBirds = SKAction.moveByX(-distanceToMoveBird, y:0, duration:NSTimeInterval(0.0040 * distanceToMoveBird));
var removeBirds = SKAction.removeFromParent();
moveAndRemoveBirds = SKAction.sequence([moveBirds, removeBirds,]);
var spawnBirds = SKAction.runBlock({() in self.spawnBird()})
var delayBirds = SKAction.waitForDuration(NSTimeInterval(4.0))
var spawnThenDelayBirds = SKAction.sequence([spawnBirds, delayBirds])
var spawnThenDelayForeverBirds = SKAction.repeatActionForever(spawnThenDelayBirds)
self.runAction(spawnThenDelayForeverBirds)
//spawning function
func spawnBird() {
var bird = SKSpriteNode()
bird.position = CGPointMake(self.frame.size.width + crowTexture1.size().width * 2, 0);
var height = UInt32(self.frame.size.height/1)
var height_max = UInt32(500)
var height_min = UInt32(500) //300
var y = arc4random_uniform(height_max - height_min + 1) + height_min;
var bird1 = SKSpriteNode(texture: crowTexture1)
bird1.position = CGPointMake(0.0, CGFloat(y))
bird1.physicsBody = SKPhysicsBody(rectangleOfSize: bird1.size)
bird1.physicsBody?.dynamic = false
bird1.physicsBody?.categoryBitMask = crowCategory
bird1.physicsBody?.collisionBitMask = catCategory | scoreCategory
bird1.physicsBody?.contactTestBitMask = 0
bird.addChild(bird1)
bird.runAction(moveAndRemoveBirds)
birds.addChild(bird)
}
感謝您的評論,我一直在玩弄你的代碼,我喜歡這個概念,我似乎無法將它與我的代碼整合在一起,只有一隻鳥在一定的高度範圍內從右到左進入屏幕。這隻鳥需要穿過整個屏幕,因爲這是觸發器,一旦鳥碰到屏幕左側的觸點,就會增加分數......如果您或其他人知道如何做到這一點,那就是我尋找,我會很感激。 –