I want to set the width of a node to be the distance between a moving node and a fixed node. In other words, I hope that the width of the node changes as another node moving. Is there a function to do this ?
Use the hypot
function:
let distance = hypot(movingNode.position.x - fixedNode.Position.x, movingNode.position.y - fixedNode.Position.y)
This returns the length of the hypotenuse of a right-angle triangle of width x and height y, which we can envisage as being drawn with your two nodes being on the non-right angled vertices.
https://developer.apple.com/documentation/coregraphics/1456251-hypot
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.