i am experimenting on this open source app game with an old version of cocos2d
i have successfully inserted enemies and have collision detected also... now i want
is to put on some projectiles to make it look more awesome however i tried ray's tutorial
This one
but the projectiles still aren't shooting..
PS: my target is moving or jumping rather..
here is what i did:
Code:
-(void)TouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];
AtlasSprite *bird = (AtlasSprite *) [spriteManager getChildByTag:kBird];
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[Director sharedDirector]convertCoordinate:location];
CGSize winSize = [[Director sharedDirector]winSize];
Sprite *projectile = [Sprite spriteWithFile:@"psn.png"];
projectile.position = ccp(bird.position.y,bird.position.x);
int offX = location.x - projectile.position.x;
int offY = location.y - projectile.position.y;
[self addChild:projectile];
int realX = winSize.width + (projectile.contentSize.width/2);
float ratio = (float) offY / (float) offX;
int realY = (realX *ratio) + projectile.position.y;
CGPoint realDest = ccp(realX, realY);
int offRealX = realX - projectile.position.x;
int offRealY = realY - projectile.position.y;
float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY));
float velocity = 480/1;
float realMoveDuration = length/velocity;
[projectile runAction:[Sequence actions:[MoveTo actionWithDuration:realMoveDuration position:realDest],
[CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)], nil]];
}
i hope someone could help and that would be great