3
\$\begingroup\$

I have some code in a project already, but I'd like to change it up a bit. Currently, my code creates an empty node called _buttonLayer and then create some buttons to add to it. My buttons start from the top-left corner of the _buttonLayer and then get added all the way to the bottom-right corner.

// Set up button layer.
_buttonLayer = [SKNode node];
_buttonLayer.position = CGPointMake(_centerOfScreen.x - (_buttonSize.width * 1.5) - 5.0,
                                    self.size.height - ((self.size.height * 0.375) + (_buttonSize.height) - 50.0) + 5.0);
[self addChild:_buttonLayer];


// Set up button array.
_buttonArray = [NSMutableArray array];


// Add some buttons.
for (char row = 0; row < 4; row++) {
    for (char col = 0; col < 4; col++) {

        // Buttons.
        SKSpriteNode *button = [SKSpriteNode spriteNodeWithImageNamed:@"LightGreyButton"];
        button.name = @"LightGreyButton"; // Initially set it to grey, because they all start off that way.
        button.size = _buttonSize;
        button.position = CGPointMake(2.0 + ((button.size.width + 3.0) * col),
                                      -(2.0 + ((button.size.height + 3.0) * row)));
        [_buttonLayer addChild:button];
        [_buttonArray addObject:button];

    }
}

So what I need to do now is create the buttons in a circle – instead of in a square. I'd like to somehow add the buttons into an outline of a circle, and then take the whole _buttonLayer and rotate it. Of course, the way I have it right now, it rotates on the top-left corner of the square. I want the middle of the circle to rotate.

How would I go about doing this?

\$\endgroup\$

closed as off-topic by Josh Oct 19 '16 at 15:17

  • This question does not appear to be about game development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ I'm voting to close this question as off-topic because it is a cross-network post \$\endgroup\$ – Josh Oct 19 '16 at 15:17
0
\$\begingroup\$

You can rotate the entire _buttonLayer if you make it a SKSpriteNode a subclass of SKNode. You will have access to the default anchorPoint property that is already set in the middle of the SKSpriteNode object. (0.5,0.5) is the center. You will want to set its color property to clearColor so you have the same appearance as you would with using a SKNode. You will have access to the zRotation property of SKNode on your SKSpriteNode as well. That is one way of doing it.

It seems like two questions really? It might be better breaking them up. One for laying buttons out in a circle and the other for rotation. Hope that helps?

\$\endgroup\$
  • \$\begingroup\$ Thanks for your help, @Robert, but someone on stackoverflow.com answered my problem. The link is here. \$\endgroup\$ – Christian Kreiter Nov 8 '15 at 1:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.