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

Method init

tests/cpp-tests/Source/Box2DTest/Box2dTest.cpp:52–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52bool Box2DTest::init()
53{
54 if (!TestCase::init())
55 {
56 return false;
57 }
58 auto dispatcher = Director::getInstance()->getEventDispatcher();
59
60 auto touchListener = EventListenerTouchAllAtOnce::create();
61 touchListener->onTouchesEnded = AX_CALLBACK_2(Box2DTest::onTouchesEnded, this);
62 dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
63
64 // init physics
65 this->initPhysics();
66 // create reset button
67 this->createResetButton();
68
69 // Set up sprite
70#if 1
71 // Use batch node. Faster
72 auto parent = SpriteBatchNode::create("Images/blocks.png", 100);
73 _spriteTexture = parent->getTexture();
74#else
75 // doesn't use batch node. Slower
76 _spriteTexture = Director::getInstance()->getTextureCache()->addImage("Images/blocks.png");
77 auto parent = Node::create();
78#endif
79 addChild(parent, 0, kTagParentNode);
80
81 addNewSpriteAtPosition(VisibleRect::center());
82
83 auto label = Label::createWithTTF("Tap screen add boxes.\nSome objects be only visible with debug on.",
84 "fonts/Marker Felt.ttf", 12.0f);
85 addChild(label, 0);
86 label->setColor(Color3B(0, 0, 255));
87 label->setPosition(VisibleRect::center().x - 50, VisibleRect::top().y - 60);
88
89 // menu for debug layer
90 MenuItemFont::setFontSize(18);
91 auto item = MenuItemFont::create("Toggle debug", AX_CALLBACK_1(Box2DTest::toggleDebugCallback, this));
92
93 auto menu = Menu::create(item, nullptr);
94 this->addChild(menu);
95 menu->setPosition(VisibleRect::right().x - 100, VisibleRect::top().y - 60);
96
97 drawBox2D = g_debugDraw.GetDrawNode();
98 addChild(drawBox2D, 100);
99 drawBox2D->setOpacity(150);
100
101 scheduleUpdate();
102
103 return true;
104}
105
106Box2DTest::Box2DTest() : _spriteTexture(nullptr), world(nullptr) {}
107

Callers

nothing calls this directly

Calls 15

initPhysicsMethod · 0.95
createResetButtonMethod · 0.95
getInstanceFunction · 0.85
createFunction · 0.85
Color3BFunction · 0.85
topFunction · 0.85
setFontSizeFunction · 0.85
scheduleUpdateFunction · 0.85
getTextureCacheMethod · 0.80
GetDrawNodeMethod · 0.80
initFunction · 0.50

Tested by

no test coverage detected