cocos2dx吞噬

前端之家收集整理的这篇文章主要介绍了cocos2dx吞噬前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

今天花了2个小时搞吞噬层,我以前一直没用过吞噬层今天才来第一次用,也是项目上要用的,现在我将我的dOME 方法发出来,希望能给不会的童鞋们带来一点灵感。好了废话不多说了撸码开始;

#ifndef __SWALLO_ROUCH_GAME_H__
#define __SWALLO_ROUCH_GAME_H__

#include "cocos2d.h"

USING_NS_CC;

class SwalloRouchGame : public LayerColor
{
public:
    SwalloRouchGame();
    virtual ~SwalloRouchGame();

    virtual bool init() override;

    CREATE_FUNC(SwalloRouchGame);

};

#endif // !__SWALLO_ROUCH_GAME_H__
#include "SwalloRouchGame.h"


SwalloRouchGame::SwalloRouchGame()
{
}


SwalloRouchGame::~SwalloRouchGame()
{
}

bool SwalloRouchGame::init()
{
//颜色透明度设定;
    if (!LayerColor::initWithColor(Color4B(0,0,0)))
    {
        return false;
    }

    auto callback = [](Touch *,Event *)
    {
        return true;
    };
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = callback;
    listener->setSwallowTouches(true);
    _eventDispatcher->addEventListenerWithSceneGraPHPriority(listener,this);

    return true;
}
原文链接:https://www.f2er.com/cocos2dx/343405.html

猜你在找的Cocos2d-x相关文章