Change height of an SKShapeNode

本小妞迷上赌 提交于 2019-12-12 01:58:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!