问题
I have an SKShapeNode which moves down when a sprite gets close to the top of the screen. However I can't seem to change the height of the frame.
Changing the property directly gives me the error 'Expression is not assignable'.
So I tried this code:
//Move the world down
world.position = CGPointMake(0.0f, -(20.0f));
SKAction* moveDown = [SKAction moveToY:(world.position.y - 50.0f) duration:1];
[world runAction:moveDown];
CGRect temp = world.frame;
temp.size.height = (world.frame.size.height / 1.2);
world.frame = temp;
but it says I can't assign the frame as it's read-only.
回答1:
The frame of an SKShapeNode is read-only. If you would like to change the node's height, you can replace this
CGRect temp = world.frame;
temp.size.height = (world.frame.size.height / 1.2);
world.frame = temp;
with this
world.yScale = 1.0 / 1.2;
来源:https://stackoverflow.com/questions/26977654/change-height-of-an-skshapenode