Apple Game Frameworks and Technologies: fadeIn to alpha 1.0 when alpha was already 1.0 (p 143)

On page 143 is this code:

// Add the 'chomp' text at the player's position
let chomp = SKLabelNode(fontNamed: "Nosifer")
chomp.name = "chomp"
chomp.fontSize = 22.0
chomp.text = "gloop"
chomp.horizontalAlignmentMode = .center
chomp.verticalAlignmentMode = .bottom
chomp.position = CGPoint(x: player.position.x, y: player.frame.maxY + 25)
chomp.zRotation = CGFloat.random(in: -0.15...0.15)
addChild(chomp)

// Add actions to fade in, rise up, and fade out
let fadeIn = SKAction.fadeAlpha(to: 1.0, duration: 0.05)
let fadeOut = SKAction.fadeAlpha(to: 0.0, duration: 0.45)
let moveUp = SKAction.moveBy(x: 0.0, y: 45, duration: 0.45)
let groupAction = SKAction.group([fadeOut, moveUp])
let removeFromParent = SKAction.removeFromParent()
let chompAction = SKAction.sequence([fadeIn, groupAction, removeFromParent]) 
chomp.run(chompAction)

The fadeIn action fades alpha to 1.0 over 0.05 seconds. It is the first action in the sequence. But the label node hasn’t had its alpha tweaked and the default is already 1.0. So the fadeIn action, as it is currently written, is just adding a small delay but no fade.

Question:

Was it intended for this to actually fade? If so then we should add chomp.alpha = 0 to the upper code block. If not then perhaps the fadeAlpha action should just be a wait action?

Admittedly nobody will ever notice the difference either way due to the very short duration of 0.05 seconds. But I feel like the code doesn’t match the intent right now. I’m just not sure what the intent was.

2 Likes