Search code examples
sprite-kitskspritenodesklabelnode

Scaling a SKSpriteNode without its children being scaled


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?


Solution

  • 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.