cocos2d может вращаться более чем на 360. но если вы идете влево и вправо, то это немного сложнее, чем просто проверка, если sprite.rotation == 1080
.если вращение происходит по вашему touchesMoved
методу, то вам следует записать максимальное вращение (возможно, вращение вправо) и самое низкое вращение (наоборот), и тогда разница должна быть больше 360 * 3.так что добавьте 2 класса в ваш слой G float maxRot,minRot;
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
maxRot = mySprite.rotation; // here you set the ivars to defaults.
minRot = mySprite.rotation; // im setting them to your sprite initial rotation
} // incase it is not 0
в конце вашего touchesMoved
метода, который вы проверите для своих условий:
if (mySprite.rotation > maxRot)
maxRot = mySprite.rotation;
else if (mysprite.rotation < minRot)
minRot = mySprite.rotation;
if ((maxRot - minRot) >= (360*3)) {
// your condition is satisfied
}
я не проверял это такэто может быть просто неправильно ... но это стоит попробовать
РЕДАКТИРОВАТЬ:
приведенный выше код не будет работать, если вращения не происходят в одном направлении ... он не будет работать для вас,левое, правильное состояние.Я предполагаю, что один из способов - отслеживать направление вашего вращения в touchesMoved
.так что опять вам понадобится класс vars
int numOfRots;
float previousRot, currentRot, accumRot;
BOOL isPositive, isPreviousPositive;
ваши методы касания:
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
previousRot = mySprite.rotation;
currentRot = mySprite.rotation;
accumRot = 0;
numOfRots = 0;
isPositive = NO;
isPreviousPositive = NO;
}
в конце touchesMoved
у вас будет следующее:
currentRot = mySprite.rotation;
if (currentRot > previousRot)
isPositive = YES;
else
isPositive = NO;
if (isPositive != isPreviousPositive) {
// now we have a change in direction, reset the vars
accumRot = 0;
}
if (isPositive) {
accumRot += abs(currentRot - previousRot);
}
else {
accumRot += abs(previousRot - currentRot);
}
if (accumRot >= 360) {
//now we have one rotation in any direction.
numOfRots++;
//need to reset accumRot to check for another rot
accumRot = 0;
if (numOfRots == 3) {
//BINGO!!! now you have 3 full rotations
}
}
previousRot = currentRot;
isPreviousPositive = isPositive;
надеюсь, это поможет