今天花了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;
}