zoukankan      html  css  js  c++  java
  • 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);
            }
  • 相关阅读:
    抛弃【 LIMIT O,N 】,换种方法查询分页
    在美国,男 / 女卫生间(厕所)的正确称呼为什么?请用英语写出答案。
    CSS3 选择器
    使用Git将项目上传到github
    Elasticsearch 的 Update更新
    elasticsearch 基本用法
    elasticsearch 基础性操作
    elasticsearch 插入数据
    elasticsearch 安装和部署
    关于httpclient 请求https (如何绕过证书验证)
  • 原文地址:https://www.cnblogs.com/YZFHKMS-X/p/12695308.html
Copyright © 2011-2022 走看看