你好朋友我希望在Sprite move.i上实现CCMotionStreak效果后触摸事件。但是现在我在Sprite路径移动后实现了。
我的代码如下所示只有事件
-(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];
}
}