Hey all so I am working on a game right now where I have 3 sprites and they follow the finger at a certain speed. Each sprite is at a different speed. Im using ccTouchesMoved and if you select one and drag it will follow and also face the finger. The only problem is that when I move my finger the sprite turns perfectly but it will stop moving until I stop moving my finger. Once i start moving it stops again. here is the code that im using.
-(BOOL) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{//event that starts when a finger touchs the screen
UITouch *touch = [touches anyObject];
CGPoint tmpLoc = [touch locationInView: [touch view]];
CGPoint location = [[Director sharedDirector] convertCoordinate:tmpLoc];
NSUInteger i, count = [allPlayerSprites count];
for (i = 0; i < count; i++) {
PlayerSprite * obj = (PlayerSprite *)[allPlayerSprites objectAtIndex:i];
if (obj.canFlag) {
if(location.x < 240){
obj.canTrack = NO;//The object that we touched cant be tracked anymore.
obj.canFlag = YES;
obj.moving = YES;
[obj stopAllActions];
[obj runAction: [MoveTo actionWithDuration:1 position:ccp(location.x, location.y)]];
float o = location.x - [obj position].x;
float a = location.y - [obj position].y;
float at = (float) CC_RADIANS_TO_DEGREES( atanf( o/a) );
if( a > 0 ) {
if( o > 0 )
at = 180 + abs(at);
else
at = 180 - abs(at);
}
[obj setRotation:at];
}
}
}
return kEventHandled;
}
Any ideas on how I can fix this?
-Korki