我想为我的游戏启用多点触控。但我不知道如何实现CCMotionStreak的多点触控版本。每当我用两根手指触摸2个点时,中间会出现一条色带。我想要的是每根手指的一条丝带。 如果我能在粒子系统中做到这一点我会更好,但基本上我面临同样的问题。 有人之前做过吗?就像水果忍者一样。
答案 0 :(得分: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];
}
}