我正在尝试将5帧的动画合并到我现有的spwn中的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)
}