CCsprite在ios中从一个点转移到另一个点后的CCMotionStreak?

时间:2013-12-06 07:21:58

标签: ios cocos2d-iphone

你好朋友我希望在Sprite move.i上实现CCMotionStreak效果后触摸事件。但是现在我在Sprite路径移动后实现了。

enter image description here

我的代码如下所示只有事件

-(id) init
{
    if( (self=[super init]))
    {

    self.touchEnabled = YES;
    CCMotionStreak *torpedoStreak = [CCMotionStreak streakWithFade:1.7f minSeg:10 width:10 color:ccWHITE textureFilename:@"Button1.png"];
    [torpedoStreak setPosition:torpedoOne.position];
    [self addChild:torpedoStreak z:2];
    }
 }


-(void)createMotionStreak:(NSInteger)touchHash
{
    streak = [CCMotionStreak streakWithFade:1.7f minSeg:10 width:10 color:ccWHITE textureFilename:@"Button1.png"];
    [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.position = point;

    //[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];
    }

}

0 个答案:

没有答案