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 Pragmatic Bookshelf topics Top

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
Razor54672
The answer to 3rd Problem of Chapter 5 (Making Choices) of “Practical Programming, Third Edition” seems incorrect in the given answer ke...
New
telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=> (create-...
New
mikecargal
Title: Hands-on Rust: question about get_component (page 295) (feel free to respond. “You dug you’re own hole… good luck”) I have somet...
New
jskubick
I’m running Android Studio “Arctic Fox” 2020.3.1 Patch 2, and I’m embarrassed to admit that I only made it to page 8 before running into ...
New
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
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
dachristenson
I’ve got to the end of Ch. 11, and the app runs, with all tabs displaying what they should – at first. After switching around between St...
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’...
1020 16979 374
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
New
PragmaticBookshelf
Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
New
AstonJ
Biggest jackpot ever apparently! :upside_down_face: I don’t (usually) gamble/play the lottery, but working on a program to predict the...
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
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New

Latest in Apple Game Frameworks and Technologies

Apple Game Frameworks and Technologies Portal