I follow the tutorial on the simple cocos2d game .
however, in this tutorial, bullets that are launched by the user are in only one direction
What can I do to make it work in all directions, not only on one side?
here is the direction code.
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]];
All help would be greatly appreciated. Thanks
source share