【Cocosd2d实例教程七】Cocos2d实现超炫的粒子效果!!
生活随笔
收集整理的這篇文章主要介紹了
【Cocosd2d实例教程七】Cocos2d实现超炫的粒子效果!!
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
(轉載請注明出處:http://blog.csdn.net/buptgshengod)
1.介紹
? ? ?你想擁有炫酷的效果么,你想讓你的應用亮瞎別人的狗眼么!!不要急,這里告訴大家怎么實現絢麗的粒子效果! 先上個圖,點擊界面產生火焰!(依舊是動態的,只是作者懶得截動態圖)2.實現部分
? ? ?1)軟件的安裝
? ? 我們通過軟件ParticleDesigner設計如圖中的效果,在下面會給出這款軟件的破解版!使用起來還是很簡單的,安裝了之后,打開進入如下界面, ? ?? 任選一款雙擊可以進行編輯,這里就不講怎么編輯了,點擊save as到出,記得要把到出設為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 valueif( (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下載地址
文章源碼
總結
以上是生活随笔為你收集整理的【Cocosd2d实例教程七】Cocos2d实现超炫的粒子效果!!的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Cocosd2d实例教程六】Cocos
- 下一篇: 【Cocosd2d实例教程八】Cocos