DropCharge, Ch17 Juice... coins stop spinning?

On page 482/483 we programmatically make the coins (template) use the animated (spinning) coins. This looks great until the player jumps high enough to start using the addRandomForegroundOverlay() method. At this point, the coins stop being animated (spinning). I tried this using the Ch17/resources/final version, i.e., the author’s version (I don’t trust my personal coding that much) and found the exact same thing.

It sure seems like the coins should spin no matter how high the player jumps.

Two questions: 1) has anyone else seen this, and 2) what’s the fix? I like the idea of creating static textures in the builder and replacing them with animated versions in code, but this doesn’t seem very reliable.

I noticed the same thing I’ve emailed Ray wenderlich but haven’t heard back yet.

I noticed the same bug. It’s in all versions up through the Section IV: Juice, final Chapter 17 Challenge project.

The same here too…

Anyone know what’s the problem could be?

I can’t explain the problem, and I’ve also reported it to the authors for comment.

Here’s a workaround:
Rather than just animating coins in the template, explicitly call animate(with:timeperframe:) for coins after you add each new dynamic overlay that includes coins.

Major Steps:

  1. Create two new properties to hold the SKAction for coin animation.
  2. Load these two properties with textures via setupAnimationWithPrefix(…)
  3. Write a new helper function addAnimationToOverlay(overlay:)
  4. Call this helper function in createForegroundOverlay(…) before adding to the fgNode.

Here are code extracts:

// 7. Coin Actions
var coinAnimationNormal:        SKAction!
var coinAnimationSpecial:       SKAction!
override func didMove(to view: SKView) {
    // Load textures for spinning coins
    coinAnimationNormal   = setupAnimationWithPrefix("powerup05_",            start: 1, end: 6, timePerFrame: 0.1)
    coinAnimationSpecial  = setupAnimationWithPrefix("powerup01_",            start: 1, end: 6, timePerFrame: 0.1)
func addAnimationToOverlay(overlay: SKSpriteNode) {
    overlay.enumerateChildNodes(withName: "Coin") { (node, stop) in
        var newNode = SKSpriteNode()
        if let nodePhysicsBody = node.physicsBody {
            switch nodePhysicsBody.categoryBitMask {
            case PhysicsCategory.CoinNormal:
                newNode = self.coin.copy() as! SKSpriteNode
            case PhysicsCategory.CoinSpecial:
                newNode = self.coinSpecial.copy() as! SKSpriteNode
                newNode = node.copy() as! SKSpriteNode
            newNode.position = node.position

func createForegroundOverlay(…) {

addAnimationToOverlay (overlay: foregroundOverlay)


orangephoenix code works perfectly, but must add Load textures in didMove as the first/top 2 lines of code (before setups).

Otherwise, you may …
fatal error: unexpectedly found nil while unwrapping an Optional value
in func addAnimationToOverlay(overlay: SKSpriteNode)

When will this code be fixed ?!?!?

orangephoenix code works but you will need to reassign the contactBitMask to the special coin again.

newNode.physicsBody?.contactTestBitMask = PhysicsCategory.Player

I noticed the same bug.
For some reason it only seems to affect devices running iOS 10, since coins are animated just fine on my iPad running iOS 9.3.3, but they stop animating on my iPhone running iOS 10.3.1.

I, as well, have no idea what’s the reason behind it since it doesn’t seem to make any sense, but in the meantime my workaround was pretty much the same as orangephoenix suggested, altho I actually created different classes for the Player, Coin, Platform and Lava to have stuff a bit more sorted.

It’d be cool to know what’s causing the bug if only just out of curiosity.

This issue still exists. I’m on iOS 10.3.3

Thanks for the workaround orangephoenix