在Spritenode动画和运动期间出现红色大x

时间:2015-11-10 11:22:27

标签: skspritenode sktextureatlas

这是我每隔一秒向场景中添加一个动画精灵的问题。当我向zoombie节点添加另一个子动画zoombie时,有时它会加载动画纹理,而其他时候会显示为红色大X. enter image description here

func addMonster() {

        let zoombieSprite = SKSpriteNode(color: SKColor.greenColor(), size: CGSizeMake(40, 60))

        // Determine where to spawn the monster along the Y axis
        let actualY = randRange(lower: zoombieSprite.size.height, upper: size.height - zoombieSprite.size.height)
        // Position the monster slightly off-screen along the right edge,
        // and along a random position along the Y axis as calculated above
        zoombieSprite.position = CGPoint(x: size.width + zoombieSprite.size.width/2, y: actualY)
        zoombieSprite.physicsBody = SKPhysicsBody(rectangleOfSize: zoombieSprite.size) // 1
        zoombieSprite.physicsBody?.dynamic = true // 2
        zoombieSprite.physicsBody?.categoryBitMask = PhysicsCategory.Monster // 3
        zoombieSprite.physicsBody?.contactTestBitMask = PhysicsCategory.Projectile // 4
        zoombieSprite.physicsBody?.collisionBitMask = PhysicsCategory.None // 5

        addChild(zoombieSprite)


        //zoombieSprite.addChild(createAnimatedZoombie())

        let zoombieAnimation = SKAction.runBlock({
            zoombieSprite.addChild(self.createAnimatedZoombie())

        })



        // Determine speed of the monster
        let actualDuration = randRange(lower: 6.0, upper: 10.0)
        //print("actualDuration = \(actualDuration)")

        let actionMove = SKAction.moveTo(CGPoint(x: -zoombieSprite.size.width/2, y: actualY), duration: NSTimeInterval(actualDuration))

        // Create the actions
        let actionMoveDone = SKAction.removeFromParent()


        zoombieSprite.runAction(SKAction.sequence([zoombieAnimation ,actionMove,actionMoveDone]))
    }


 //MARK: - ANIMATE FRAME AND MOVE ZOOMBIE
    func createAnimatedZoombie () -> SKSpriteNode {

        let animatedZoobieNode = SKSpriteNode(texture: spriteArray[0])

        let animationFrameAction = SKAction.animateWithTextures(spriteArray, timePerFrame: 0.2)

        let durationTime = SKAction.waitForDuration(0.1)

        let repeatAction = SKAction.repeatActionForever(animationFrameAction)

        let quenceAction = SKAction.sequence([durationTime, repeatAction])

        animatedZoobieNode.runAction(quenceAction)

        return animatedZoobieNode
    }

1 个答案:

答案 0 :(得分:0)

非常感谢我尊敬的兄弟 Joseph Lord 并感谢上帝我通过将sprite kit atlas array count属性除以2解决了我的问题因为在这个文件夹中我放了@ 2x和@ 3x图像因此,当我以前从这个atlas文件夹中获取图像数量时,它曾用于返回添加了@ 2x和@ 3x图像的数字。