Creating modal layers
In user interface design, a modal layer is an important layer. A modal layer is like a child window. When a modal layer is showing, players cannot touch any other button outside the modal layer. They can only touch the button on the modal layer. We will need modal layers when we confirm something with the players. In this recipe, we will explain how to create modal layers.
How to do it...
Firstly, you have to two new files named ModalLayer.h
and ModalLayer.cpp
. They should contain the following code:
ModalLayer.h
should have the following code:
#include "cocos2d.h" USING_NS_CC; class ModalLayer : public Layer { public: ModalLayer(); ~ModalLayer(); bool init(); CREATE_FUNC(ModalLayer); void close(Ref* sender=nullptr); }; ModalLayer.cpp should have the following code: #include "ModalLayer.h" USING_NS_CC; ModalLayer::ModalLayer() { } ModalLayer::~ModalLayer() { } bool ModalLayer::init() { if (!Layer::init()) { return false; } auto listener = EventListenerTouchOneByOne...