Question

How can i shoot the sprite "ink" straight up? The player Squiddy moves across the screen and i would like it to shoot the ink up, straight up, everytime. The code i have so far shoots the ink but it shoots it to a certain point on the screen

The code

CGPoint targetPosition = ccp(self.contentSize.width/2, self.contentSize.height/2 + self.contentSize.height);

ink = [CCSprite spriteWithImageNamed:@"MarioTube_Body_Rev.png"];
ink.position = Squiddy.position;
ink.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:ink.contentSize.width/2.0f andCenter:ink.anchorPointInPoints];
ink.physicsBody.collisionGroup = @"playerG roup";
ink.physicsBody.collisionType  = @"projectileCollision";
CCActionRotateBy *actionSpin = [CCActionRotateBy actionWithDuration:.5f angle:360];
[ink runAction:[CCActionRepeatForever actionWithAction:actionSpin]];
[_physicsWorld addChild:ink];

CCActionMoveTo *actionMove   = [CCActionMoveTo actionWithDuration:.75f position:targetPosition];
CCActionRemove *actionRemove = [CCActionRemove action];
[ink runAction:[CCActionSequence actionWithArray:@[actionMove,actionRemove]]];
Was it helpful?

Solution

As I said before, try to apply a force or impulse to ink.physicsBody:

CGPoint force = ccpMult(ccp(0,90), 600); //x=0, y=90, force=600
[ink.physicsBody applyForce:force];

With a value of x=0, the force will go up. Just play with the values. Hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top