skellt

skellt

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.

Marked As Solved

Paradox927

Paradox927

Author and Editor at PragProg

Hi, David.

Thanks for the message.

To answer your question, the code you see in the book does indeed match the intent behind it.

For this label, I wanted a very subtle fade in effect to help prevent a jarring visual response from the player. The 0.05 seconds works to achieve this.

Of course, if you’d rather skip the fadeIn action, increase its duration, or use a wait action instead, that works too.

It’s always fun to see what others come up with on their own. There was a reader on Twitter who shared his progress with the game, and he added some extra code that randomly changes the text. I thought it was well done and added some extra charm to our blobby little green friend. :grin:

Thanks again for your comments. I appreciate all of the feedback you’re giving about this book.

EDIT: My apologies, I looked a little closer at the code, and you’re right—I am missing the initial setting of chomp.alpha = 0.0. You’ll see this correction in the next update.

Popular Prag Prog topics Top

New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
gilesdotcodes
In case this helps anyone, I’ve had issues setting up the rails source code. Here were the solutions: In Gemfile, change gem 'rails' t...
New
swlaschin
The book has the same “Problem space/Solution space” diagram on page 18 as is on page 17. The correct Problem/Solution space diagrams ar...
New
fynn
This is as much a suggestion as a question, as a note for others. Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
andreheijstek
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New
dachristenson
I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1016 16836 371
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
foxtrottwist
Here’s our thread for the Keyboardio Atreus. It is a mechanical keyboard based on and a slight update of the original Atreus (Keyboardio ...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
DevotionGeo
I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
New
PragmaticBookshelf
Author Spotlight: Bruce Tate @redrapids Programming languages always emerge out of need, and if that’s not always true, they’re defin...
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New

Latest in PragProg

View all threads ❯