Rob
Rob

Reputation: 26334

cocos2d: Why can't I change a scaled node's position?

I think I'm just understanding scaling/positioning nodes/layers incorrectly. I'm setting up my node like this (node class is derived from CCNode):

-(id) init
{
    if ((self = [super init]))
    {
        // Create parallax background node.
        background = [BackgroundNode node];
        [self addChild:background z:0];

        // Create foreground node.
        foreground = [ForegroundLayer node];
        [self addChild:foreground z:0];

        self.position.y = 500.0f;
        self.scaleX = 1.5f;
        self.scaleY = 1.5f;
    }

    return self;
}

It doesn't seem to matter what I set the self.position.y to - the scaled node is always displayed as though it was positioned in the bottom-left of the screen. I've tried playing around with anchorPoint as well, but it doesn't really seem to change anything.

The reason I'm asking is because I'd like to be able to pan vertically when I'm zoomed in - this doesn't seem to really be the right way to accomplish it, though. Any ideas?

Upvotes: 0

Views: 196

Answers (1)

Kazuki Sakamoto
Kazuki Sakamoto

Reputation: 14009

self.position.y = 500.0f;

doesn't work. It should be

self.position = ccp(self.position.x, 500.0f);

Please refer to "Cocoa Objective-c Property C structure assign fails".

Upvotes: 2

Related Questions