4

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 - enter image description here

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?

stevecross
  • 5,588
  • 7
  • 47
  • 85
Viper
  • 1,408
  • 9
  • 13
  • physics bodies don't "scale", once created a body retains the size of its shape - if you want to change it you have to create a new body – CodeSmile Feb 13 '15 at 12:33
  • physics body is scaling actually.. i cross checked it by setting self.view?.showsPhysics = true and its clearly visible that its scaling. – Viper Feb 13 '15 at 12:36

1 Answers1

2

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.

Viper
  • 1,408
  • 9
  • 13