切片效果如何在Fruit Ninja游戏中起作用?

时间:2011-02-09 10:59:36

标签: iphone slice

有人知道切片效果在Fruit Ninja游戏中是如何工作的吗?

screenshot of Fruit Ninja game

还是以其他方式达到类似的效果?

如何获得所有滑动指向如何绘制线条 请帮帮....

2 个答案:

答案 0 :(得分:1)

我绘制了许多线来提供切片效果并从可变数组中同时删除了点我将点放到绘制线

代码: -

-(void)init
    {
     [self checkAllArray];
     [self schedule:@selector(removePoints:) interval:0.0001f];
    }
-(void)checkAllArray
{
    if (naughtytoucharray==NULL)
        naughtytoucharray=[[NSMutableArray alloc] init];
    else
    {
        [naughtytoucharray release];
        naughtytoucharray=nil;
        naughtytoucharray=[[NSMutableArray alloc] init];
    }
}

-(void)draw
{
    glEnable(GL_LINE_SMOOTH);
    glColor4ub(255, 255, 255, 255); //line color 
    //glLineWidth(2.5f);
    for(int i = 0; i < [naughtytoucharray count]; i+=2)
    {
        CGPoint start = CGPointFromString([naughtytoucharray objectAtIndex:i]);
        CGPoint end = CGPointFromString([naughtytoucharray objectAtIndex:i+1]);
                ccDrawLine(start, end); // line 1
        ccDrawLine(ccp(start.x-2,start.y-2),ccp(end.x-2,end.y-2));// line 2
        ccDrawLine(ccp(start.x-4,start.y-4),ccp(end.x-4,end.y-4));// line 3
        ccDrawLine(ccp(start.x-6,start.y-6),ccp(end.x-6,end.y-6));// line 4
        ccDrawLine(ccp(start.x-8,start.y-8),ccp(end.x-8,end.y-8));// line 5
    }
}

- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    CGPoint new_location = [touch locationInView: [touch view]];
    new_location = [[CCDirector sharedDirector] convertToGL:new_location];
    CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
    oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];
    [naughtytoucharray addObject:NSStringFromCGPoint(new_location)];
    [naughtytoucharray addObject:NSStringFromCGPoint(oldTouchLocation)];
}

-(void)removePoints:(ccTime *)tm
{
    if ([naughtytoucharray count]>0)
    {
        [naughtytoucharray removeObjectAtIndex:0];
    }
}

-(void)dealloc
{
    //NSLog(@"deallocing lightning\n");
    [self removeAllChildrenWithCleanup:YES];
    [super dealloc];
}

答案 1 :(得分:0)

屏幕空间中有多个控制点。然后插入它们并构建沿该曲线的多个多边形。您可以使用片段着色器绘制边框或纹理(但我认为它会更难)。