Game Development Reference
In-Depth Information
#import "CCSprite.h"
@interface SpringBoard : CCSprite
-(void) letGo;
@end
The goal is to temporarily disable the distance joint. Unfortunately, you can only invalid-
ate (remove) a joint. So, to reset the springboard, you'll have to create a new distance joint
instance in code and give it the same properties as the previously deleted joint. The easiest
way to do so is to keep a reference to the joint even after it has been invalidated by simply
not using the __weak keyword on the ivar. This makes _lockJoint a strong reference,
meaning the joint assigned to the ivar will not deallocate until the SpringBoard in-
stance itself deallocates.
Add the highlighted code of Listing 9-2 to SpringBoard.m . Note that the listing shows
only the first half of the class, not the entire implementation. Most importantly, don't re-
move the @end .
Listing 9-2 . Finding and assigning the _lockJoint distance joint
#import "SpringBoard.h"
@implementation SpringBoard
{
CCPhysicsJoint* _lockJoint; // Notice: not using
__weak here!
}
-(void) didLoadFromCCB
{
Class distanceJointClass
= NSClassFromString(@"CCPhysicsSlideJoint");
for (CCPhysicsJoint* joint in self.physicsBody.joints)
{
if ([joint isKindOfClass:distanceJointClass])
{
_lockJoint = joint;
break;
}
}
}
Search WWH ::




Custom Search