2012-03-23 2 views
1

У меня есть классы жестов, доступные с example, чтобы поддержать Rcognition Gesture. У меня есть 4 спрайта в верхнем слое, которые нужно перемещать по прокрутке влево/вправо и иметь 3 спрайта для прокрутки на нижнем слое.Как сгладить прокрутку Parallax с помощью жестового удара

У меня есть следующий код

-(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--; 
} 

Я не могу Размах вправо/влево Плавно дает перекрытие верхнево слоя. Пожалуйста, помогите мне сгладить движение слоя.

Любой вид Помощь будет Оценил

Благодаря ...

ответ

0

Ваш вопрос звучит похоже на проблемы я, и другие, столкнулись с облицовочных спрайтов и границ между ними. Попробуйте добавить это в начало записи об инициализации:

[[CCDirector sharedDirector] setProjection:CCDirectorProjection2D]; 
+0

Я пробовал свой код, но он не работает. Он перемещается с промежутком между двумя верхними слоями. – Marine

+0

@Marine. Если бы у вас был шанс опубликовать снимок этого пробела? Это может быть сложно, если оно появляется только во время движения, но я не совсем понимаю, что вы видите, и что должно произойти. – BobbyScon

Смежные вопросы