coco2d-x中引用离子效果,游戏计数的方法

来源:互联网 发布:极品飞车ol mac 编辑:程序博客网 时间:2024/05/02 03:00

引用粒子效果主要是在游戏中实现例如炸弹爆炸效果的实现,首先可以利用离子编辑器编辑你需要的效果,这里给大家推荐一款软件——particle designer  这款软件可以进行编辑离子效果,我用的还不错。

这里给大家贴一段代码 第一段是普通的动画实现效果,第二段是离子编辑效果。

Boom * Boom::createBoom(int type,int x,int y){

    Boom * newB=Boom::create();å

    Sprite * sp=nullptr;

    

    //添加纹理和动画

    switch (type) {

        case 1://第一种爆炸效果

        {sp=Sprite::create("boom.png",Rect(0,0,44,49));

            sp->setPosition(x,y);

            sp->setScale(2);

            newB->addChild(sp);

            Vector<SpriteFrame*> allframe;

            for (int i=0; i<7; i++) {

                SpriteFrame* sf=SpriteFrame::create("boom.png",

                                                   Rect(i*44,0,44,49));

                           allframe.pushBack(sf);

 }

            auto animation=Animation::createWithSpriteFrames(allframe);

            animation->setDelayPerUnit(0.05);

            auto ani=Animate::create(animation);

            //action 序列

            auto act=Sequence::create(ani,CallFunc::create(CC_CALLBACK_0(Boom::killMe, newB)), NULL);

            sp->runAction(act);

        }

            break;


 case2://2种爆炸效果

        {

            auto particle=ParticleSystemQuad::create("boom1.plist");

            newB->addChild(particle);

            particle->setPosition(x,y);

            //action 序列

            auto act=Sequence::create(DelayTime::create(1),CallFunc::create(CC_CALLBACK_0(Boom::killMe, newB)), NULL);

            newB->runAction(act);

        }

            break;

            

    }

    

 return newB;

需要注意的事这两端代码都需要进行回掉

void Boom::killMe(){

    this->removeFromParentAndCleanup(true);

      

进行释放 2计数

首先引入ui组件

#include"cocosGui.h"  uisng namespace ui;

调用 TextAtlas组件在Game.h中 int m_score;

在 Game.cpp中初始化分数 m_score=0

case 1:this->m_score+=100;

case2:this->m_score+=300;

this->m_score=0;

auto tscore=TextAtlas::create("0","",,“0”);//这里的零我忘什么意思了 明天解释

this->addChild(tscore)

tscore->setTag(111);

auto  score==(TextAtals*)this->getChildByTag(111);

char ms[15="0000000"

int tmp=m_score/100;

int end =6;

while tmp!0){

ms[end]='/0'

tmp=tmp /10;

end--;

score->setstring(String Utils::format(%s%d,ms,m_score);

}



0 0
原创粉丝点击