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

Method init

tests/cpp-tests/Source/BugsTest/Bug-914.cpp:31–72  ·  view source on GitHub ↗

on "init" you need to initialize your instance

Source from the content-addressed store, hash-verified

29
30// on "init" you need to initialize your instance
31bool Bug914Layer::init()
32{
33 // always call "super" init
34 // Apple recommends to re-assign "self" with the "super" return value
35 if (BugsTestBase::init())
36 {
37 auto listener = EventListenerTouchAllAtOnce::create();
38 listener->onTouchesBegan = AX_CALLBACK_2(Bug914Layer::onTouchesBegan, this);
39 listener->onTouchesMoved = AX_CALLBACK_2(Bug914Layer::onTouchesMoved, this);
40 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
41
42 // ask director the the window size
43 auto size = Director::getInstance()->getWinSize();
44 LayerColor* layer;
45 for (int i = 0; i < 5; i++)
46 {
47 layer = LayerColor::create(Color4B(i * 20, i * 20, i * 20, 255));
48 layer->setContentSize(Size(i * 100.0f, i * 100.0f));
49 layer->setPosition(size.width / 2, size.height / 2);
50 layer->setAnchorPoint(Vec2(0.5f, 0.5f));
51 layer->setIgnoreAnchorPointForPosition(false);
52 addChild(layer, -1 - i);
53 }
54
55 // create and initialize a Label
56 auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 64.0f);
57 auto item1 = MenuItemFont::create("restart", AX_CALLBACK_1(Bug914Layer::restart, this));
58
59 auto menu = Menu::create(item1, nullptr);
60 menu->alignItemsVertically();
61 menu->setPosition(size.width / 2, 100);
62 addChild(menu);
63
64 // position the label on the center of the screen
65 label->setPosition(size.width / 2, size.height / 2);
66
67 // add the label as a child to this Layer
68 addChild(label);
69 return true;
70 }
71 return false;
72}
73
74void Bug914Layer::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
75{

Callers

nothing calls this directly

Calls 12

createFunction · 0.85
getInstanceFunction · 0.85
Color4BFunction · 0.85
alignItemsVerticallyMethod · 0.80
initFunction · 0.50
SizeFunction · 0.50
Vec2Function · 0.50
setContentSizeMethod · 0.45
setPositionMethod · 0.45
setAnchorPointMethod · 0.45

Tested by

no test coverage detected