2011-03-24 55 views
0

我想为我的游戏启用多点触控。但我不知道如何实施CCMotionStreak的多点触控版本。每次我用2个手指触摸2点,就会出现一条缎带。我想要的是每个手指一条丝带。 我会更好,如果我可以在粒子系统中做到这一点,但基本上我面临同样的问题。 之前有人做过这个吗?就像水果忍者一样。CCMotionStreak或粒子系统的cocos2d多点触控

回答

2

您需要为每次触摸创建一个CCMotionStreak节点。

例如:

-(void)createMotionStreak:(NSInteger)touchHash 
{ 
    CCMotionStreak* streak = [CCMotionStreak streakWithFade:1.7f minSeg:10 image:@"arrow.png" width:32 length:32 color:ccc4(255, 0, 255, 255)]; 
    [self addChild:streak z:5 tag:touchHash]; 
} 

-(void)removeMotionStreak:(NSInteger)touchHash 
{ 
    [self removeChildByTag:touchHash cleanup:YES]; 
} 

-(CCMotionStreak*)getMotionStreak:(NSInteger)touchHash 
{ 
    CCNode* node = [self getChildByTag:touchHash]; 
    if(![node isKindOfClass:[CCMotionStreak class]]) { 
     [self createMotionStreak:touchHash]; 
    } 
    return (CCMotionStreak*)node; 
} 

-(void) addMotionStreakPoint:(CGPoint)point on:(NSInteger)touchHash 
{ 
    CCMotionStreak* streak = [self getMotionStreak:touchHash]; 
    [streak.ribbon addPointAt:point width:32]; 
} 

-(CGPoint)locationFromTouch:(UITouch*)touch 
{ 
    CGPoint touchLocation = [touch locationInView: [touch view]]; 
    return [[CCDirector sharedDirector] convertToGL:touchLocation]; 
} 

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSEnumerator* enumerator = [touches objectEnumerator]; 
    UITouch* oneTouch = nil; 
    while (oneTouch = [enumerator nextObject]) { 
     [self addMotionStreakPoint:[self locationFromTouch:oneTouch] on:oneTouch.hash]; 
    } 
} 

-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSEnumerator* enumerator = [touches objectEnumerator]; 
    UITouch* oneTouch = nil; 
    while (oneTouch = [enumerator nextObject]) { 
     [self removeMotionStreak:oneTouch.hash]; 
    } 
}