1

我添加了示例中可用的手势类以支持手势识别。我在顶层有 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--;
}

我无法平滑地向右/向左滑动它会产生顶层的重叠。请帮助我平滑图层移动。

任何形式的帮助将不胜感激

谢谢...

4

1 回答 1

0

您的问题听起来与我和其他人面临的平铺精灵和它们之间的边界的问题相似。尝试将其添加到 init 语句的顶部:

[[CCDirector sharedDirector] setProjection:CCDirectorProjection2D];
于 2012-03-27T17:35:06.470 回答