【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 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下载地址

文章源码

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值