zoukankan      html  css  js  c++  java
  • Cocos2d-x3.1颗粒使用

    1、头

    #include "cocos2d.h"
    USING_NS_CC;
    
    class WaterWaveDemo : public Layer
    {
    public:
        static cocos2d::Scene* createScene();
        
        // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
        virtual bool init();
        
        // a selector callback
        void menuCloseCallback(cocos2d::Ref* pSender);
        
        // implement the "static create()" method manually
        CREATE_FUNC(WaterWaveDemo);
    };

    2、cpp文件

    #include "WaterWaveDemo.h"
    #include "SimpleAudioEngine.h"
    using namespace CocosDenshion;
    
    Scene* WaterWaveDemo::createScene()
    {
        // 'scene' is an autorelease object
        auto scene = Scene::create();
        
        // 'layer' is an autorelease object
        auto layer = WaterWaveDemo::create();
        
        // add layer as a child to scene
        scene->addChild(layer);
        
        // return the scene
        return scene;
        
    }
    
    bool WaterWaveDemo::init()
    {
        bool bRet = false;
        do{
            CC_BREAK_IF(!Layer::init());
            
            auto listener = EventListenerTouchOneByOne::create();
            listener->setSwallowTouches(true);
            
            listener->onTouchBegan = [&](Touch* touch,Event* event){
              
                auto touchPosition = touch->getLocation();
                ParticleSystemQuad* mParticle = ParticleSystemQuad::create("showClick.plist");
                mParticle->setScale(0.5);
                mParticle->setPosition(touchPosition);
                mParticle->setAutoRemoveOnFinish(true);
                addChild(mParticle);
                
                return false;
            };
            
            Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
            bRet = true;
        }while(0);
        return bRet;
    }
    
    void WaterWaveDemo::menuCloseCallback(Ref* pSender)
    {
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
    	MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
        return;
    #endif
        
        Director::getInstance()->end();
        
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        exit(0);
    #endif
    }
    代码下载:http://download.csdn.net/detail/yuxikuo_1/7861203

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    kali 无线网络渗透测试
    kali 漏洞扫描
    Python复杂多重排序
    《编写高质量代码:改善Python程序的91个建议》读后感
    Python用format格式化字符串
    CDH安装Hadoop
    Python设计模式——状体模式
    HBase的安装与使用
    Python设计模式——观察者模式
    Python设计模式——建造者模式
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4722450.html
Copyright © 2011-2022 走看看