Resizing a SKShapeNode

2020-06-22 05:08发布

问题:

How do I resize a SKShapeNode?

What I've tried so far:

Frame resize

box.frame.width = 10

Gives the error Cannot assign to the result of this expression

SKAction

let actionResize = SKAction.resizeToWidth(10, duration: NSTimeInterval(0.1))
box.runAction(actionResize)

Nothing happens

xScale

box.xScale = 0.1

Scales the node instead of resizing

回答1:

The action, resizeToWidth, can be called by an SKSpriteNode.

You can call the action, scaleTo , with SKShapeNode.



回答2:

Change it to a var:

var shapeNodeName = SKShapeNode(rectOfSize: CGSizeMake(100,100))

// change to new size - shape will now be 150 x 150
shapeNodeName = SKShapeNode(rectOfSize: CGSizeMake(150,150))