Game Development Reference
In-Depth Information
The anchor and distance properties have been entered as they were in SpriteBuilder. That,
too, is a bit unfortunate because technically the
_lockJoint
instance still has all these
properties internally. However, you'd have to go through a private Objective-C API (a
private property named
constraint
) to gain access to another private
Chip-
munkConstraint
class. In this case, the anchor and distance properties are unlikely to
change, so you can just enter them in code.
The newly created joint is assigned directly to
_lockJoint
, replacing the previous one.
Since the previous lock joint has no strong reference holding on to it, ARC will automat-
ically release its memory. So you really just keep the most recently created
_lockJoint
in memory. And once the
SpringBoard
instance deallocates, the remaining
_lock-
Joint
instance will also deallocate.
The
CCPhysicsJoint
class allows you to create the same joints in code as the ones
you can edit in SpriteBuilder (pivot, spring, and distance). However, variations exist that
you can achieve only with SpriteBuilder. For instance, you can't create a pivot joint with
for a reference of available
CCPhysicsJoint
initializers.
Listing 9-5
.
Creating CCPhysicsJoint instances
// Creating a Spring Joint
+(CCPhysicsJoint*)connectedSpringJointWithBodyA:(CCPhysicsBody*)bodyA
bodyB:(CCPhysicsBody*)bodyB
anchorA:(CGPoint)anchorA
anchorB:(CGPoint)anchorB
restLength:(CGFloat)restLength
stiffness:(CGFloat)stiffness
damping:(CGFloat)damping;
// Creating a Distance Joint
+(CCPhysicsJoint*)connectedDistanceJointWithBodyA:(CCPhysicsBody*)bodyA
bodyB:(CCPhysicsBody*)bodyB
anchorA:(CGPoint)anchorA
anchorB:(CGPoint)anchorB;
+(CCPhysicsJoint*)connectedDistanceJointWithBodyA:(CCPhysicsBody*)bodyA
bodyB:(CCPhysicsBody*)bodyB
anchorA:(CGPoint)anchorA
anchorB:(CGPoint)anchorB
Search WWH ::
Custom Search