#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
}