• cocos2d-X create std colorlayer


    #ifndef __MUSICLAYER_H__
    #define __MUSICLAYER_H__
    #include "cocos2d.h"
    using namespace std;
    using namespace cocos2d;
    
    
    
    class MusicLayer:public LayerColor
    {
    public:
        void inits();
        void free();
        MusicLayer();
        ~MusicLayer();
    private:
        void OnCallback(cocos2d::Ref* pSender);
        virtual bool onTouchBegan(Touch *touch, Event *unused_event);
    
    
    
    };
    #endif // !__MUSICLAYER_H__
    #include "MusicLayer.h"
    #include "cocos/ui/UIButton.h"
    #include "SimpleAudioEngine.h"
    #define DISPLAY Director::getInstance()->getVisibleSize()
    #define displayex Director::getInstance()->getVisibleSize()
    
    MusicLayer::MusicLayer()
    {
        this->inits();
    }
    
    MusicLayer::~MusicLayer()
    {
        this->free();
    }
    
    void MusicLayer::free()
    {
    
    }
    
    void MusicLayer::inits()
    {
        log("MusicLayer init");
        this->setTouchEnabled(true);
        auto ELTOBO = EventListenerTouchOneByOne::create();
        ELTOBO->setSwallowTouches(true);
        ELTOBO->onTouchBegan = std::move(std::bind(&MusicLayer::onTouchBegan, this, std::placeholders::_1, std::placeholders::_2));
        this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(ELTOBO, this);
        //this->getEventDispatcher()->addEventListenerWithFixedPriority();
        //this->getEventDispatcher()->addCustomEventListener();
    
    
        string file("res/Button.png");
        auto b = cocos2d::ui::Button::create(file, file, file);
        b->setColor(Color3B(24, 48, 64));
        b->setPosition(displayex / 2);
        b->setPressedActionEnabled(true);
        b->setContentSize(Size(200, 100));
        b->setTitleColor(Color3B::BLUE);
        b->addClickEventListener(std::bind(&MusicLayer::OnCallback, this, std::placeholders::_1));
        this->addChild(b);
    
    }
    
    void MusicLayer::OnCallback(cocos2d::Ref* pSender)
    {
        string name = ((Node*)(pSender))->getName();
        if (name == "")
        {
    
        }
    }
    
    bool MusicLayer::onTouchBegan(Touch *pTouch, Event *pEvent)
    {
        log("touch MusicLayer");
        return true;
    }
            auto musicLayer = new (std::nothrow) MusicLayer();
            if (musicLayer && musicLayer->initWithColor(Color4B(12, 24, 32, 255)))
            {
                musicLayer->setPosition(0, DISPLAY.height);
                musicLayer->runAction(MoveTo::create(0.1f, Vec3(0, 0, 0)));
                musicLayer->autorelease();
                this->addChild(musicLayer);
            }
  • 相关阅读:
    Java-JUC(四):同步容器介绍
    Java-JUC(三):原子性变量与CAS算法
    Java:双向链表反转实现
    Java-JUC(二):Java内存模型可见性、原子性、有序性及volatile具有特性
    Java-JUC(一):volatile引入
    TSQL:判断某较短字符串在较长字符串中出现的次数。
    二叉树的定义与前序、中序、后序遍历
    c#:判断一个数组元素中否有重复元素
    c#:对两个字符串大小比较(不使用c#/java内部的比较函数),按升序排序
    mysql之 OPTIMIZE TABLE整理碎片
  • 原文地址:https://www.cnblogs.com/YZFHKMS-X/p/12695308.html
Copyright © 2020-2023  润新知