Reputation: 161
Im working on a iOS GAME. Now I need to create a CCSprite in my function and want it to float into the sky. Here is the code:
CCSprite *corpse =[[CCSprite alloc] initWithImageNamed:@"kid_dead.png"];
corpse.physicsBody.type=CCPhysicsBodyTypeDynamic;
corpse.physicsBody.allowsRotation=true;
corpse.physicsBody.affectedByGravity=false;
corpse.physicsBody.velocity=self.kid.physicsBody.velocity;
[self._physicsNode addChild:corpse];
corpse.physicsBody.velocity=CGPointMake(0.0f,10.0f);
However, it seems like the corpse appears like static and not physics-enabled. Anyone can offer some suggestion? Many thanks:)
Upvotes: 1
Views: 211
Reputation: 64477
You first need to create a physics body and assign it before changing any of its properties:
CCSprite *corpse = [CCSprite spriteWithImageNamed:@"kid_dead.png"];
corpse.physicsBody = [CCPhysicsBody bodyWithRadius:10 andCenter:CGPointMake(0, 0)];
You find those functions in the CCPhysicsBody class reference.
Upvotes: 2