Physics body size not changing with SKSpriteNode s

2019-06-23 22:23发布

问题:

I am trying to create a spring launcher where when touch is moved on scene the spring will coil as much the touch is dragged down and thn launch the item above the spring on touch end method. For that i changed the size and position of SKSpriteNode in touch move method as -

launcher.position               =   CGPointMake(frame.size.width*0.97, launcher.position.y-1)
launcher.size                   =   CGSizeMake(frame.size.width*0.05, launcher.frame.size.height-2)

But the Physics body of SKSpriteNode not changing it comes like this -

Please help.. And if a change physics body of SKSpriteNode than it lags on device too much..

let springTexture    =   SKTexture(imageNamed: "spring-wire")
launcher.physicsBody = SKPhysicsBody(texture: springTexture, size: launcher.size)
launcher.physicsBody?.dynamic = false

Is there any way to change size of Physics body after creating it once?

回答1:

I fixed it by changing the yScale of SKSpriteNode insteade of changing its size in touchesMoved method

launcher.yScale =   launcher.yScale-0.008
launcher.position  =   CGPointMake(frame.size.width*0.97, launcher.size.height/2)

I don't know if this is the right approach or not but by this SKSpriteNode's physics body change accordingly.