【Cocosd2d实例教程七】Cocos2d实现超炫的粒子效果!!
生活随笔
收集整理的這篇文章主要介紹了
【Cocosd2d实例教程七】Cocos2d实现超炫的粒子效果!!
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
(轉(zhuǎn)載請(qǐng)注明出處:http://blog.csdn.net/buptgshengod)
1.介紹
? ? ?你想擁有炫酷的效果么,你想讓你的應(yīng)用亮瞎別人的狗眼么!!不要急,這里告訴大家怎么實(shí)現(xiàn)絢麗的粒子效果! 先上個(gè)圖,點(diǎn)擊界面產(chǎn)生火焰!(依舊是動(dòng)態(tài)的,只是作者懶得截動(dòng)態(tài)圖)2.實(shí)現(xiàn)部分
? ? ?1)軟件的安裝
? ? 我們通過(guò)軟件ParticleDesigner設(shè)計(jì)如圖中的效果,在下面會(huì)給出這款軟件的破解版!使用起來(lái)還是很簡(jiǎn)單的,安裝了之后,打開(kāi)進(jìn)入如下界面, ? ?? 任選一款雙擊可以進(jìn)行編輯,這里就不講怎么編輯了,點(diǎn)擊save as到出,記得要把到出設(shè)為cocos2d項(xiàng),這樣把生成的.plist文件放到xcode的resource中去!
? ? 2)代碼實(shí)現(xiàn)部分
? ? 把效果加進(jìn)去很簡(jiǎn)單,關(guān)鍵是實(shí)現(xiàn)點(diǎn)擊屏幕事件。 首先,打開(kāi)HelloWorldLayer.m,清理init()函數(shù)中沒(méi)用的部分。 -(id) init {// always call "super" init// Apple recommends to re-assign "self" with the "super's" return valueif( (self=[super init]) ) {self.isTouchEnabled=YES;//這句是自己加進(jìn)去的}return self; } 接著,注冊(cè)toutch事件,在外面添加下列函數(shù) -(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];//這三句是確定點(diǎn)擊屏幕的位置CCParticleRain *rain=[CCParticleRain node];//選擇的是CCParticle中的Rain模式,其實(shí)有很多種[self addChild:rain z:1];//有人會(huì)問(wèn)z是什么意思,z的數(shù)值是指層次,z大的成員在小的上面rain.position=touchLocation;CCParticleSystemQuad *fire=[CCParticleSystemQuad particleWithFile:@"fire.plist"];[self addChild:fire z:1];//加入資源fire.position = touchLocation;}
依舊是貢獻(xiàn)出源代碼以及工具
ParticleDesigner下載地址
文章源碼
總結(jié)
以上是生活随笔為你收集整理的【Cocosd2d实例教程七】Cocos2d实现超炫的粒子效果!!的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【Cocosd2d实例教程六】Cocos
- 下一篇: 【Cocosd2d实例教程八】Cocos