Earlier Question Was Never Answered!

The following question was asked, but never answered. Let me ask it again. This is the text of the original question. I’m not sure about the page number. The statement appears twice in Chapter 9.

"Page 236 of the book describes positioning the catAwake sprite @ CGPoint(x: -30, y: 100).

The commentary describes this: “You set the node’s position to make sure that it will appear exactly over the existing texture.”

Can someone explain how to calculate the values of -30 and 100? I’ve looked at the positioning of the original shared_cat sprite and can’t figure it out, but I’m sure there’s an explanation. I want to understand the calculation so I can do the same with my own shapes in the future.

Thanks. "

That’s an interesting puzzle. I had to hunt around a while to sort it out.

The key is this line in GameScene.swift:

   catNode = childNode(withName: "//cat_body") as! CatNode

You aren’t getting a reference to cat.sks, but to cat_body. If you look at cat.sks, you will see that the body is not at (0, 0), but is at (22, -112), according to the instructions. The other parts of the cat are then relative to the body, so they can be animated.

For CatWakeUp.sks and CatCurl.sks, the cats are anchored at the center, or (0,0). So they need to be offset from the position of cat_body. I can’t say why it is (-30, 100), instead of (-22, 112), except that it may match them up better, or it is just rounded off to get close enough.

1 Like

Thanks for the solution. I’m sure you are correct about the explanation and slight discrepency. Perhaps the author would like to comment. Thanks again. Cheers!

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.