Я добавил классы жестов, доступные из примера , для поддержки распознавания жестов.У меня есть 4 спрайта в верхнем слое, которые нужно переместить с помощью пролистывания влево / вправо, и 3 спрайта для смахивания на нижнем слое.
У меня есть следующий код
-(id) init
{
// Some Stuff
[Gestures sharedGestures].swipeTolerance = 40;
[Gestures sharedGestures].pointResetLimit = 10;
[Gestures sharedGestures].delegate = self;
[Gestures sharedGestures].useX = NO;
[Gestures sharedGestures].useCircle = NO;
[Gestures sharedGestures].useSquare = NO;
for (int i=1; i<6; i++)
{
NSString *str=[NSString stringWithFormat:@"Howtoplay_0%d.png",i];
topLayer[i]=[CCSprite spriteWithFile:str];
[topLayer[i] setPosition:ccp(640/2,480/2)];
[self addChild:topLayer[i] z:1];
[topLayer[i] setVisible:NO];
}
[topLayer[1] setVisible:YES];
[topLayer[1] setPosition:ccp(320/2,480/2)];
for (int i=1; i<4; i++)
{
NSString *str=[NSString stringWithFormat:@"HowtoplayB_0%d.png",i];
backLayer[i]=[CCSprite spriteWithFile:str];
[backLayer[i] setPosition:ccp((320*i)/2,480/2)];
[self addChild:backLayer[i] z:-1];
}
[backLayer[1] setPosition:ccp(320/2,480/2)];
}
-(void) registerWithTouchDispatcher{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:1 swallowsTouches:YES];
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
[[Gestures sharedGestures] reset];
return TRUE;
}
-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint point = [touch locationInView: [touch view]];
CGPoint converted = [[CCDirector sharedDirector] convertToGL:point];
[[Gestures sharedGestures] addPoint:converted];
}
-(void) swipeLeftComplete
{
NSLog(@"Swipe Left Complete Called");
[self MoveLeft];
}
-(void) swipeRightComplete
{
[self MoveRight];
}
-(void)MoveLeft
{
[topLayer[currentTop+1] setPosition:ccp(640/2,480/2)];
[topLayer[currentTop+1] setVisible:YES];
[topLayer[currentTop] runAction:[CCMoveTo actionWithDuration:2 position:ccp(-320/2,480/2)]];
[topLayer[currentTop+1] runAction:[CCMoveTo actionWithDuration:2 position:ccp(320/2,480/2)]];
[topLayer[currentTop-1] setVisible:NO];
currentTop+=1;
}
-(void) MoveRight
{
[topLayer[currentTop-1] setVisible:YES];
[topLayer[currentTop] setVisible:YES];
[topLayer[currentTop] runAction:[CCMoveTo actionWithDuration:2 position:ccp(-320/2,480/2)]];
[topLayer[currentTop-1] runAction:[CCMoveTo actionWithDuration:2 position:ccp(320/2,480/2)]];
currentTop--;
}
Я не могу плавно провести вправо / влево, это дает перекрытие верхнего слоя.Пожалуйста, помогите мне сгладить движение слоя.
Любая помощь будет оценена
Спасибо ...