| 94 | } |
| 95 | |
| 96 | bool Box2DTestBed::initWithEntryID(int entryId) |
| 97 | { |
| 98 | if (!TestCase::init()) |
| 99 | { |
| 100 | return false; |
| 101 | } |
| 102 | auto director = Director::getInstance(); |
| 103 | Vec2 visibleOrigin = director->getVisibleOrigin(); |
| 104 | Size visibleSize = director->getVisibleSize(); |
| 105 | |
| 106 | m_entryID = entryId; |
| 107 | |
| 108 | m_entry = g_testEntries + entryId; |
| 109 | m_test = m_entry->createFcn(); |
| 110 | |
| 111 | debugDrawNode = g_debugDraw.GetDrawNode(); |
| 112 | m_test->debugDrawNode = debugDrawNode; |
| 113 | m_test->g_debugDraw = g_debugDraw; |
| 114 | |
| 115 | TestCase::addChild(debugDrawNode, 100); |
| 116 | |
| 117 | // init physics |
| 118 | this->initPhysics(); |
| 119 | |
| 120 | auto label = Label::createWithTTF(m_entry->name, "fonts/arial.ttf", 28); |
| 121 | TestCase::addChild(label, 1); |
| 122 | label->setPosition(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height - 50); |
| 123 | |
| 124 | // Adds touch event listener |
| 125 | _touchListener = EventListenerTouchOneByOne::create(); |
| 126 | _touchListener->setSwallowTouches(true); |
| 127 | _touchListener->onTouchBegan = AX_CALLBACK_2(Box2DTestBed::onTouchBegan, this); |
| 128 | _touchListener->onTouchMoved = AX_CALLBACK_2(Box2DTestBed::onTouchMoved, this); |
| 129 | _touchListener->onTouchEnded = AX_CALLBACK_2(Box2DTestBed::onTouchEnded, this); |
| 130 | TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_touchListener, 10); |
| 131 | |
| 132 | // Adds Keyboard event listener |
| 133 | _keyboardListener = EventListenerKeyboard::create(); |
| 134 | _keyboardListener->onKeyPressed = AX_CALLBACK_2(Box2DTestBed::onKeyPressed, this); |
| 135 | _keyboardListener->onKeyReleased = AX_CALLBACK_2(Box2DTestBed::onKeyReleased, this); |
| 136 | TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_keyboardListener, 11); |
| 137 | |
| 138 | auto _mouseListener = EventListenerMouse::create(); |
| 139 | _mouseListener->onMouseMove = AX_CALLBACK_1(Box2DTestBed::onMouseMove, this); |
| 140 | _mouseListener->onMouseUp = AX_CALLBACK_1(Box2DTestBed::onMouseUp, this); |
| 141 | _mouseListener->onMouseDown = AX_CALLBACK_1(Box2DTestBed::onMouseDown, this); |
| 142 | _mouseListener->onMouseScroll = AX_CALLBACK_1(Box2DTestBed::onMouseScroll, this); |
| 143 | TestCase::_eventDispatcher->addEventListenerWithFixedPriority(_mouseListener, 12); |
| 144 | |
| 145 | // Demo messageString |
| 146 | labelDebugDraw = Label::createWithTTF("TEST", "fonts/arial.ttf", 8.0f); |
| 147 | labelDebugDraw->setAnchorPoint(Vec2(0, 1)); |
| 148 | labelDebugDraw->setPosition(VisibleRect::left().x, VisibleRect::top().y - 10); |
| 149 | labelDebugDraw->setColor(Color3B::WHITE); |
| 150 | TestCase::addChild(labelDebugDraw, 100); |
| 151 | |
| 152 | TestCase::scheduleUpdate(); |
| 153 |
no test coverage detected