2012-03-23 117 views
1

我已添加可從example獲得的手勢類別以支持手勢識別。 我有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--; 
} 

我無法刷卡左/右順利它給頂層的重疊。請幫助我平滑圖層移動。

任何一種幫助的可以理解的

謝謝...

回答

0

你的問題聽起來很相似,我和其他人,都面臨着與他們之間的拼接精靈和邊界問題。嘗試添加到您的init語句的頂部:

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

我試過你的代碼,但它不起作用。它隨着兩個頂層之間的差距而移動。 – Marine 2012-04-05 05:33:31

+0

@海軍陸戰隊你有沒有機會發布這個差距的屏幕截圖?如果它僅在移動過程中出現,這可能會很困難,但我不太瞭解你所看到的和應該發生的事情。 – BobbyScon 2012-04-05 13:21:20