| 115 | } |
| 116 | |
| 117 | bool Menu::initWithArray(const Vector<MenuItem*>& arrayOfItems) |
| 118 | { |
| 119 | if (Node::initLayer()) |
| 120 | { |
| 121 | _enabled = true; |
| 122 | // menu in the center of the screen |
| 123 | Vec2 s = _director->getWinSize(); |
| 124 | |
| 125 | this->setIgnoreAnchorPointForPosition(true); |
| 126 | setAnchorPoint(Vec2(0.5f, 0.5f)); |
| 127 | this->setContentSize(s); |
| 128 | |
| 129 | setPosition(s.width / 2, s.height / 2); |
| 130 | |
| 131 | int z = 0; |
| 132 | |
| 133 | for (auto&& item : arrayOfItems) |
| 134 | { |
| 135 | this->addChild(item, z); |
| 136 | z++; |
| 137 | } |
| 138 | |
| 139 | _selectedItem = nullptr; |
| 140 | _state = Menu::State::WAITING; |
| 141 | |
| 142 | // enable cascade color and opacity on menus |
| 143 | setCascadeColorEnabled(true); |
| 144 | setCascadeOpacityEnabled(true); |
| 145 | |
| 146 | auto touchListener = EventListenerTouchOneByOne::create(); |
| 147 | touchListener->setSwallowTouches(true); |
| 148 | |
| 149 | touchListener->onTouchBegan = AX_CALLBACK_2(Menu::onTouchBegan, this); |
| 150 | touchListener->onTouchMoved = AX_CALLBACK_2(Menu::onTouchMoved, this); |
| 151 | touchListener->onTouchEnded = AX_CALLBACK_2(Menu::onTouchEnded, this); |
| 152 | touchListener->onTouchCancelled = AX_CALLBACK_2(Menu::onTouchCancelled, this); |
| 153 | |
| 154 | _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); |
| 155 | |
| 156 | return true; |
| 157 | } |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * override add: |
no test coverage detected