Question

I have a custom node that has an overridden xScale setter. E.g.:

-(void)setXScale:(CGFloat)xScale
{
    [super setXScale:xScale];
    NSLog(@"Scale changed to: %f", xScale);
}

If I set the xScale property manually, then I can see the setter being triggered.

However, if I scale the node via an action, e.g.:

[myCustomNode runAction:[SKAction scaleXTo:2.0f duration:0.5f]];

then even though the node gets correctly scaled, the setter is never invoked.

Does anybody know why not? How does the SKScale action change the node's scale?

Was it helpful?

Solution

Internally Sprite Kit uses a C++ render engine. My observation is that SKAction completely bypasses the Objective-C layer and instead will change properties directly on the C++ classes. Likely to improve the performance of actions.

If you want to observe such changes use a customActionWithDuration:actionBlock: action that sets the node's property via the block. Or you could subclass the node, add a previousScale property and periodically check if the original scale has changed by comparing it with the previousScale property.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top