【问题标题】:cocos2d multitouch for CCMotionStreak or Particle system用于 CCMotionStreak 或粒子系统的 cocos2d 多点触控
【发布时间】:2011-03-24 16:36:47
【问题描述】:

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

【问题讨论】:

    标签: iphone objective-c cocos2d-iphone multi-touch


    【解决方案1】:

    您需要为每次触摸创建一个 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];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-28
      相关资源
      最近更新 更多