I'm working on an app, this is my first time using Cocos2d, but I don't think thats my problem.
I have a piece of code here that is supposed to turn an object Clockwise when you press and hold a button, also changing its direction to go at the same angle.
Code:
id action = [RotateBy actionWithDuration:0.01 angle:1];
id seq = [Sequence actions:action, nil];
[bg2 runAction:seq];
directionIdx ++;
directionId2 ++;
if (directionId2 > 90)
directionId2 -= 90;
if (directionIdx > 360)
directionIdx -= 360;
if (directionIdx <= 360) {
if (directionIdx <= 270) {
if (directionIdx <= 180) {
if (directionIdx <= 90){
newx = 0+(1/90* directionId2);
newy = 1-(1/90* directionId2);
} else {
newx = 1-(1/90* directionId2);
newy = 0-(1/90* directionId2);
}
} else {
newx = 0-(1/90* directionId2);
newy = -1+(1/90* directionId2);
}
} else {
newx = -1+(1/90* directionId2);
newy = 0+(1/90* directionId2);
}
}
This code is to move the object in a straight line. The Timer for this function is paused while the object is turning.
Code:
-(void)MoveObject {
oldx = newx;
oldy = newy;
CGPoint currentPos = [bg2 position];
CGPoint diff = CGPointMake(oldx, oldy);
[bg2 setPosition: ccpAdd(currentPos, diff)];
}
Here is what I have thought of, but not tried:
Setting newx and newy manually for each angle in the 360 degree circle