手指效果

HelloWorld::HelloWorld()



{



    smoke=CCParticleSmoke::create();



    sun=CCParticleSun::create();



 



}



HelloWorld::~HelloWorld()



{



    smoke->setAutoRemoveOnFinish(true);



    sun->setAutoRemoveOnFinish(true);



}



 



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;



}



 



boolHelloWorld::init()



{



 



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



    bool bRet = false;



    do



    {



        CC_BREAK_IF(! CCLayer::init());



        



        CCSprite* pSprite = CCSprite::create("background.png");



        CC_BREAK_IF(! pSprite);



        pSprite->setPosition(ccp(400, 240));



this->addChild(pSprite, 0);



        



 



sun->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("fire.png"),CCRectMake(0,0,32,32));



sun->setPosition(ccp(700,350));



addChild(sun);



 



smoke->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("fire.png"),CCRectMake(0,0,32,32));



smoke->setPosition(ccp(600,150));



smoke->setLife(1);



addChild(smoke);



strike=CCMotionStreak::create(1.0,16, 16, ccWHITE, "sprite.png");



addChild(strike,1);



strike->setPosition(ccp(240,160));



 



        



        



        bRet = true;



    } while (0);



    



    return bRet;



}



bool HelloWorld::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)



{



    x=pTouch->getLocation().x;



    y=pTouch->getLocation().y;



    CCLog("ccTouchBegan");



    strike->setPosition(pTouch->getLocation());



    returntrue;



}



void HelloWorld::ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)



{



    CCLog("ccTouchMoved");



    getLine(pTouch->getLocation());



    strike->setPosition(pTouch->getLocation());



}



void HelloWorld::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)



{



    if(fabs(pTouch->getLocation().x-x)<20&&fabs(pTouch->getLocation().y-y)<20)



    {



        getBoom(pTouch->getLocation());



    }



    CCLog("ccTouchEnded");



}



 



voidHelloWorld::getLine(CCPoint pt)



{



    cocos2d::CCParticleSystemQuad *mSystem=CCParticleSystemQuad::create("Particle.plist");



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



                                ,CCRectMake(0,0,32,32));



    mSystem->setPosition(pt);



    mSystem->setDuration(0.3f);



    mSystem->setLife(0.5f);



    addChild(mSystem);



    mSystem->setAutoRemoveOnFinish(true);



}



 



voidHelloWorld::getBoom(CCPoint pt)



{



    



    CCParticleSystemQuad*mSystem2 = CCParticleSystemQuad::create("Boom.plist");



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



                                 ,CCRectMake(0,0,32,32));



    mSystem2->setPosition(pt);



    mSystem2->setDuration(0.05f);



    addChild(mSystem2);



    mSystem2->setAutoRemoveOnFinish(true);



}

 

你可能感兴趣的:(效果)