I'm trying to incorporate an animation of 5 frames into my existing spawn function for a spritenode. Currently a crow moves across the screen from right to left, I would like to animate this however no matter what I try I keep generating Thread 1 errors.
By commenting out certain bits of code I can either animate the bird in a static position on screen or move the bird from right to left but not animated (comment out spawn func).
I know the below code wont work in it's current form but it's everything I'm working with, hopefully someone can help me.
Below is all my code I'm trying to slot together...
Thank you,
//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)
}