MCPcopy Create free account
hub / github.com/axmolengine/axmol / initWithArray

Method initWithArray

core/2d/Menu.cpp:117–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117bool 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:

Callers 1

createWithArrayMethod · 0.45

Calls 9

addChildMethod · 0.95
createFunction · 0.85
Vec2Class · 0.70
setPositionFunction · 0.70
setAnchorPointFunction · 0.50
setContentSizeMethod · 0.45
setSwallowTouchesMethod · 0.45

Tested by

no test coverage detected