heres my touch method code:
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
location = [[CCDirector sharedDirector] convertToGL:location];
//setup initial location of bullet
CCSprite *bullet = [CCSprite spriteWithFile:@"bullet.png"
rect:CGRectMake(0, 0, 10, 10)];
bullet.position = ccp(_tankGood.x + 15.0, _tankGood.y);
int offX = location.x - _tankGood.x;
int offY = location.x - _tankGood.y;
[self addChild:bullet];
float length = sqrtf((offX*offX)+(offY*offY));
velocity = 480/2;
float realMoveDuration = length/velocity;
[bullet runAction:[CCSequence actions:
[CCMoveTo actionWithDuration:realMoveDuration position:location],
[CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)],
nil]];
bullet.tag = 2;
[_bullets addObject:bullet];
}
and my moving code (not sure if relevant):
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
_tankBodyGood.position = _tankGood;
_tankTurretGood.position = _tankGood;
_tankLeftBoundry = _tankBodyGood.position.x - 20.0;
_tankRightBoundry = _tankBodyGood.position.x + 20.0;
_tankTopBoundry = _tankBodyGood.position.y + 20.0;
_tankBottomBoudry = _tankBodyGood.position.y - 20.0;
if (acceleration.x < 0.0 && _tankBottomBoudry > 0.0) {
_tankGood = CGPointMake(_tankGood.x, _tankGood.y + (acceleration.x * kTGS));
}
if (acceleration.x > 0.0 && _tankTopBoundry < _winSize.height) {
_tankGood = CGPointMake(_tankGood.x, _tankGood.y + (acceleration.x * kTGS));
}
if (acceleration.y < 0.0 && _tankRightBoundry < _winSize.width) {
_tankGood = CGPointMake(_tankGood.x - (acceleration.y * kTGS), _tankGood.y);
}
if (acceleration.y > 0.0 && _tankLeftBoundry > 0.0) {
_tankGood = CGPointMake(_tankGood.x - (acceleration.y * kTGS), _tankGood.y);
}
}