【Cocosd2d实例教程7】Cocos2d实现超炫的粒子效果!

【Cocosd2d实例教程七】Cocos2d实现超炫的粒子效果!!

(转载请注明出处:http://blog.csdn.net/buptgshengod

1.介绍

     你想拥有炫酷的效果么,你想让你的应用亮瞎别人的狗眼么!!不要急,这里告诉大家怎么实现绚丽的粒子效果!
先上个图,点击界面产生火焰!(依旧是动态的,只是作者懒得截动态图)
【Cocosd2d实例教程7】Cocos2d实现超炫的粒子效果!

2.实现部分

     1)软件的安装

    我们通过软件ParticleDesigner设计如图中的效果,在下面会给出这款软件的破解版!使用起来还是很简单的,安装了之后,打开进入如下界面,【Cocosd2d实例教程7】Cocos2d实现超炫的粒子效果!     
任选一款双击可以进行编辑,这里就不讲怎么编辑了,点击save as到出,记得要把到出设为cocos2d项,
【Cocosd2d实例教程7】Cocos2d实现超炫的粒子效果!
这样把生成的.plist文件放到xcode的resource中去!

    2)代码实现部分

    把效果加进去很简单,关键是实现点击屏幕事件。
首先,打开HelloWorldLayer.m,清理init()函数中没用的部分。
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super's" return value
	if( (self=[super init]) ) {
        self.isTouchEnabled=YES;//这句是自己加进去的
	}
	return self;
}
接着,注册toutch事件,在外面添加下列函数
-(void)registerWithTouchDispatcher{
    CCDirector *director = [CCDirector sharedDirector];
    [[director touchDispatcher]addTargetedDelegate:self priority:0 swallowsTouches:YES];
}

然后就是写具体的按下事件了

-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
    
    
    
    return YES;
    
}

-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event{
    
}

-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event{
    
    CGPoint touchLocation = [touch locationInView:[touch view]];
    touchLocation = [[CCDirector sharedDirector]convertToGL:touchLocation];
    touchLocation =[self convertToNodeSpace:touchLocation];//这三句是确定点击屏幕的位置
    
    CCParticleRain *rain=[CCParticleRain node];//选择的是CCParticle中的Rain模式,其实有很多种
    [self addChild:rain z:1];//有人会问z是什么意思,z的数值是指层次,z大的成员在小的上面
    rain.position=touchLocation;
    CCParticleSystemQuad *fire=[CCParticleSystemQuad particleWithFile:@"fire.plist"];
    [self addChild:fire z:1];//加入资源
    fire.position = touchLocation;
    }



依旧是贡献出源代码以及工具

ParticleDesigner下载地址

文章源码