O'Reilly logo

Build iOS Games with Sprite Kit by Josh Smith, Jonathan Penn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using a Fixed Joint to Stick the Ball to the Plunger

Physics bodies don’t just have to drift around on their own. They can also be joined together in a variety of ways. Here, we’re going to change our RCWPlungerNode so that it joins the ball to the top of the plunger when the touch begins. That joint will hold the ball in place no matter how fast the plunger moves. When the action runs to snap the plunger back in place, we will break the joint and then launch the ball by manually applying a force to it, depending on how far the player pulled down the plunger.

First, we need to change our method declarations in RCWPlungerNode.h. The plunger needs to know more details to do its new job. We have to pass it the ball and the physics world.

06-Physics/step11/PhysicsBall/RCWPlungerNode.h ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required