I'm trying to create buttons programmatically. I have subclassed SKSpriteNode and one of its children is an SKLabelNode. The reason I did this is so that the label and button move together and are one unit. The problem is that when I scale the button, the label scales as well and it distorts the text making it look pixelated (pretty horrible). Is there a way, even if I have to rewrite the entire thing, so that I can I can scale the button only?
2 Answers
I looked for this answer for about an hour before posting this question and then the second I post the question I find the answer...unbelievable!
Setting the size of the parent (the SKSpriteNode) will affect the size of the Sprite, but not the child (the label). Here's the code:
[button setSize:CGSizeMake(100, 200)]; //button is the SKSpriteNode
The size of the label's text can be altered separately from the resizing of the button. This allows for the position of the button and it's text to remain linked, but their sizes to be controlled individually. Exactly what I needed. Perhaps there's a better solution to subclassing SKSpriteNode in the first place, but I can't think of a better way to keep them linked, yet independent.

- 1,762
- 2
- 16
- 29
Allow me to offer an alternative solution. Assuming sprite and label are the parent and child, if you scale up the sprite:
sprite.scale = 1.25;
You simply have to scale down the child label by the same amount:
label.scale = 0.75;

- 64,284
- 20
- 132
- 217
-
I thought of doing that as well. I may be wrong, but I noticed that the even if I recreate the label each time, it takes on the scale multiplier of the parent. Is there a way to avoid this without performing operations like the one you suggested? IOS 8 can't come fast enough. I hope they make it easier to build menus programmatically! – 02fentym Sep 13 '14 at 21:26
-
I know it's a super late comment but found this while searching for my own solution, but this solution wont work as `1*1.25 = 1.25` and `1.25*0.75 != 1`. You either have to multiply it by 0.8 or divide it by the same sum `1.25*0.8 = 1` and `1.25/1.25 = 1` – Vollan Apr 19 '18 at 16:19