0

Here is problem in which I add zoombie sprite to the scene every one second. When I add another sub animated zoombie to the zoombie node, sometimes it loads animated texture, and other times appear red large 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
    }
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Imran Khan
  • 9
  • 1
  • 2
  • I guess the texture isn't loaded correctly. Have you checked all the sprites are OK and included in the bundle. – Joseph Lord Nov 10 '15 at 11:51
  • Thanks very much for response zoombie nodes are temporary means these nodes would be remove when off the screen. so after every one second call addMonster() method which create monster with random speed and with animated textures. so the above all zoombie display for 2 second and then red Large x repeatedly. – Imran Khan Nov 10 '15 at 13:58
  • More explanation of the issue – Ahmed Ashour Nov 12 '15 at 12:32

1 Answers1

0

Thanks very much my respectable brother Joseph Lord and Thank God i solved my problem by just dividing sprite kit atlas array count property by 2 because in this folder i had put both @2x and @3x images so when i used to get number of images from this atlas folder it used to return the number which was addition of @2x and @3x images.

Imran Khan
  • 9
  • 1
  • 2