zoukankan      html  css  js  c++  java
  • 手指效果

    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);
    
    }
  • 相关阅读:
    FileChannel的基本使用
    qq在线交流
    ci框架连接数据库
    绩效管理,如何实现“投资于人”?
    Asp.Net开发中传递的URL的长度问题
    ASP.NET程序中常用的三十三种代码
    认识ASP.NET配置文件Web.config
    JS实现图片幻灯片效果
    一些web开发中常用的、做成cs文件的js代码
    div自适应浏览器高度的问题
  • 原文地址:https://www.cnblogs.com/jiackyan/p/3037627.html
Copyright © 2011-2022 走看看