html心碎粒子特效,cocos2d-x中自己做得一个粒子效果Demo

#include

"HelloWorldScene.h"

#include

"SimpleAudioEngine.h"

using namespace cocos2d;

using namespace CocosDenshion;

CCScene* HelloWorld::scene()

{

// 'scene' is an autorelease object

CCScene *scene = CCScene::create();

// 'layer' is an autorelease object

HelloWorld *layer = HelloWorld::create();

// add layer as a child to scene

scene->addChild(layer);

// return the scene

return scene;

}

// on "init" you need to initialize your instance

bool HelloWorld::init()

{

//

// 1. super init first

if ( !CCLayer::init() )

{

return

false;

}

/

// 2. add a menu item with "X" image,

which is clicked to quit the program

// you may modify it.

// add a "close" icon to exit the

progress. it's an autorelease object

CCMenuItemImage *pCloseItem = CCMenuItemImage::create(

"CloseNormal.png",

"CloseSelected.png",

this,

menu_selector(HelloWorld::menuCloseCallback) );

pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width

- 20, 20) );

// create menu, it's an autorelease

object

CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);

pMenu->setPosition( CCPointZero );

this->addChild(pMenu, 1);

/

//CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,false);

CCLabelTTF *titleLabel1 = CCLabelTTF::create("小果冻粒子效果Test",

"Zapfino", 20);

titleLabel1->setPosition(ccp(160,440));

CCLabelTTF *titleLabel2 = CCLabelTTF::create("点击或滑动屏幕会有效果哦",

"Zapfino", 20);

titleLabel2->setPosition(ccp(160,400));

addChild(titleLabel1,3,333);

addChild(titleLabel2,3,333);

CCParticleSystem* particleSyetem =

CCParticleRain::create();

particleSyetem->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png"));

addChild(particleSyetem);

return true;

}

void HelloWorld::onEnter(){

CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,false);

CCLayer::onEnter();

}

void HelloWorld::onExit(){

CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);

CCLayer::onExit();

}

bool HelloWorld::ccTouchBegan(CCTouch* touch, CCEvent* event){

//CCLOG("ccTouchBegan");

return true;

}

void HelloWorld::ccTouchMoved(CCTouch* touch, CCEvent* event){

CCLOG("ccTouchMoved");

getLine(touch->getLocation());

}

void HelloWorld::getLine(CCPoint pt)

{

cocos2d::CCParticleSystemQuad *mSystem=CCParticleSystemQuad::particleWithFile("himiParticle.plist");

//mSystem->initWithFile("Particle.plist");//plist文件可以通过例子编辑器获得

mSystem->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("stars.png")

,CCRectMake(0,0,32,32));//加载图片,第一个参数是纹理,第二个参数是选择图片上的位置

mSystem->setBlendAdditive(true);//这个调用必不可少

mSystem->setPosition(pt);//设置位置

mSystem->setDuration(0.03f);

mSystem->setLife(0.05f);

addChild(mSystem);

//mSystem->release();

//delete mSystem;

//CC_SAFE_DELETE(mSystem);

mSystem->setAutoRemoveOnFinish(true);

}

void HelloWorld::ccTouchEnded(CCTouch* touch, CCEvent* event){

CCLOG("ccTouchEnded");

getBoom(touch->getLocation());

}

void HelloWorld::getBoom(CCPoint pt)

{

cocos2d::CCParticleSystemQuad *mSystem2 =

CCParticleSystemQuad::particleWithFile("himiParticle.plist");

//mSystem2->initWithFile("Boom.plist");//plist文件可以通过例子编辑器获得

mSystem2->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("stars.png")

,CCRectMake(0,0,32,32));//加载图片,第一个参数是纹理,第二个参数是选择图片上的位置

mSystem2->setBlendAdditive(true);//这个调用必不可少

mSystem2->setPosition(pt);//设置位置

mSystem2->setDuration(0.05f);

addChild(mSystem2);

//mSystem2->release();

//CC_SAFE_DELETE(mSystem2);

mSystem2->setAutoRemoveOnFinish(true);

}

void HelloWorld::menuCloseCallback(CCObject* pSender)

{

CCDirector::sharedDirector()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

exit(0);

#endif

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值