on "init" you need to initialize your instance
| 144 | |
| 145 | // on "init" you need to initialize your instance |
| 146 | bool HelloWorld::init() |
| 147 | { |
| 148 | ////////////////////////////// |
| 149 | // 1. super init first |
| 150 | if ( !Layer::init() ) |
| 151 | { |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | Size visibleSize = Director::getInstance()->getVisibleSize(); |
| 156 | Point origin = Director::getInstance()->getVisibleOrigin(); |
| 157 | |
| 158 | ///////////////////////////// |
| 159 | // 2. add a menu item with "X" image, which is clicked to quit the program |
| 160 | // you may modify it. |
| 161 | |
| 162 | // add a "close" icon to exit the progress. it's an autorelease object |
| 163 | MenuItemImage *closeItem = MenuItemImage::create( |
| 164 | "CloseNormal.png", |
| 165 | "CloseSelected.png", |
| 166 | CC_CALLBACK_1(HelloWorld::menuCloseCallback,this)); |
| 167 | |
| 168 | closeItem->setPosition(origin + Point(visibleSize) - Point(closeItem->getContentSize() / 2)); |
| 169 | |
| 170 | // create menu, it's an autorelease object |
| 171 | Menu* menu = Menu::create(closeItem, nullptr); |
| 172 | menu->setPosition(Point::ZERO); |
| 173 | this->addChild(menu, 1); |
| 174 | |
| 175 | ///////////////////////////// |
| 176 | // 3. add your codes below... |
| 177 | |
| 178 | // add a label shows "Hello World" |
| 179 | // create and initialize a label |
| 180 | |
| 181 | LabelTTF* label = LabelTTF::create("Hello World", "Arial", TITLE_FONT_SIZE); |
| 182 | |
| 183 | // position the label on the center of the screen |
| 184 | label->setPosition(Point(origin.x + visibleSize.width/2, |
| 185 | origin.y + visibleSize.height - label->getContentSize().height)); |
| 186 | |
| 187 | // add the label as a child to this layer |
| 188 | this->addChild(label, 1); |
| 189 | |
| 190 | // add "HelloWorld" splash screen" |
| 191 | Sprite* sprite = Sprite::create("HelloWorld.png"); |
| 192 | |
| 193 | // position the sprite on the center of the screen |
| 194 | sprite->setPosition(Point(visibleSize / 2) + origin); |
| 195 | |
| 196 | // add the sprite as a child to this layer |
| 197 | this->addChild(sprite, 0); |
| 198 | |
| 199 | return true; |
| 200 | } |
| 201 | |
| 202 | |
| 203 | void HelloWorld::menuCloseCallback(Object* sender) |
no test coverage detected