0

这是我每隔一秒向场景添加缩放精灵的问题。当我向 zoombie 节点添加另一个子动画 zoombie 时,有时它会加载动画纹理,而其他时候会出现红色大 X。在此处输入图像描述

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
    }
4

1 回答 1

0

非常感谢我可敬的兄弟Joseph Lord 和感谢上帝,我通过将 sprite kit atlas array count 属性除以 2 解决了我的问题,因为在这个文件夹中我已经放了 @2x 和 @3x 图像,所以当我过去从这个 atlas 文件夹用于返回添加了 @2x 和 @3x 图像的数字。

于 2015-11-13T08:03:08.133 回答