简体   繁体   中英

How can I get the new CGPath that represents a scaled SKShapeNode?

An SKShapeNode that was scaled using SKActions, like this:

var shapeNode: SKShapeNode = SKShapeNode(points: UnsafeMutablePointer(points), count: points.count)  
shapeNode.runAction(SKAction.scaleTo(16, duration: 2))

I would like to then update the node's SKPhysicBody to match its new size:

shapeNode.physicsBody = SKPhysicsBody(polygonFromPath: shapeNode.path)

However, it looks like shapeNode.path returns the path at its original size, not the path at its new size.

Is there a way to get the path of the new size?

You may not use SKAction to scale the shapeNode. SKAction is just an "action", it will not change the property of a node. Try this instead:

shapeNode.xScale = 16.0
shapeNode.yScale = 16.0

Then it will return a new scaled size to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM