Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void) fireWeapon{
- //NSLog(@"Fired Weapon");
- CGSize winSize = [[CCDirector sharedDirector] winSize];
- CCSprite *projectile = [CCSprite spriteWithFile:@"projectile.png" rect:CGRectMake(0, 0, 30, 15)];
- int projectileStartX = self.weapon.contentSize.width;
- int projectileStartY = self.weapon.contentSize.height /2 + 3;
- projectile.position = ccp(projectileStartX, projectileStartY);
- [self.weapon addChild:projectile];
- //Determine where we wish to shoot the projectile to
- int realX = winSize.width + (projectile.contentSize.width/2);
- if (facing == facingLeft) {
- projectile.position = ccp(projectileStartX - projectileStartX, projectileStartY);
- projectile.rotation = 180;
- realX = -realX;
- }
- CGPoint realDest = ccp(realX, projectileStartY);
- // Determine the length of how far we're shooting
- int offRealX = realX - projectile.position.x;
- float length = sqrtf((offRealX*offRealX));
- float velocity = 480/1; // 480pixels/1sec
- float realMoveDuration = length/velocity;
- // Move projectile to actual endpoint
- [projectile runAction:[CCSequence actions:
- [CCMoveTo actionWithDuration:realMoveDuration position:realDest],
- [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)],
- nil]];
- }
- -(void)spriteMoveFinished:(id)sender {
- NSLog(@"spriteMovedFinished");
- CCSprite *sprite = (CCSprite *)sender;
- [self.weapon removeChild:sprite cleanup:YES];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement