cocos2d-x初学笔记11:粒子系统Particle

         粒子系统在游戏中模拟爆炸,光晕,燃烧,雨雪等效果,使我们游戏的画面更加绚丽,提高游戏的质量。cocos2d-x中有许许多多的特定效果粒子系统,我们选择其中模拟火把燃烧的粒子系统进行讲解。其他的粒子效果请大家自行了解,它们的用法都是差不多的。

        (注意:我使用的cocos2d-x版本是2.0.4,系统是win7)下载地址

         新建项目ParticleTest我们先导入燃烧粒子效果需要的图片,从D:\cocos2d-2.0-x-2.0.4\samples\TestCpp\Resources\Images(你的目录有可能不一样)找到fire.png复制到我们自己的项目中的Resources文件夹,然后在VS中右击项目选择添加->现有项,添加刚刚复制的图片到我们的项目ParticleTest即可。

         修改HelloWorld.cpp文件的init()函数如下

bool HelloWorld::init()
{
    bool bRet = false;
    do 
    {
        //
        // super init first
        //

        CC_BREAK_IF(! CCLayer::init());

        //
        // add your codes below...
        //

        // 1. Add a menu item with "X" image, which is clicked to quit the program.

        // Create a "close" menu item with close icon, it's an auto release object.
        CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
            "CloseNormal.png",
            "CloseSelected.png",
            this,
            menu_selector(HelloWorld::menuCloseCallback));
        CC_BREAK_IF(! pCloseItem);

        // Place the menu item bottom-right conner.
        pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));

        // Create a menu with the "close" menu item, it's an auto release object.
        CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
        pMenu->setPosition(CCPointZero);
        CC_BREAK_IF(! pMenu);

        // Add the menu to HelloWorld layer as a child layer.
        this->addChild(pMenu, 1);

	//取得屏幕大小
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	//新建一个粒子系统,类型为火
        CCParticleSystem* m_emitter = CCParticleFire::create();
        //设置粒子系统的渲染纹理
        m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png") );
	//设置粒子的位置
	m_emitter->setPosition( ccp(size.width/2,size.height/2) );

        //添加到布景中
        addChild(m_emitter, 1);
        bRet = true;
    } while (0);

    return bRet;
}

运行程序,我们会看到在屏幕的中央出现一个类似于火把燃烧的粒子系统。

                   

由于是初学笔记,各种功能做的都比较简单,主要是为了初学者更好的学习用法,还请谅解。

最后祝愿每一个奋斗在路上的人早日实现梦想!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值