diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp index f4f9a1c878..86924143ad 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.cpp @@ -188,6 +188,12 @@ bool Box2DView::initWithEntryID(int entryId) _eventDispatcher->addEventListenerWithFixedPriority(listener, -10); _touchListener = listener; + auto keyboardListener = EventListenerKeyboard::create(); + keyboardListener->onKeyPressed = CC_CALLBACK_2(Box2DView::onKeyPressed, this); + keyboardListener->onKeyReleased = CC_CALLBACK_2(Box2DView::onKeyReleased, this); + _eventDispatcher->addEventListenerWithFixedPriority(keyboardListener, -11); + _keyboardListener = keyboardListener; + return true; } @@ -222,6 +228,7 @@ Box2DView::~Box2DView() { // Removes Touch Event Listener _eventDispatcher->removeEventListener(_touchListener); + _eventDispatcher->removeEventListener(_keyboardListener); delete m_test; } // @@ -239,7 +246,7 @@ bool Box2DView::onTouchBegan(Touch* touch, Event* event) auto nodePosition = convertToNodeSpace( touchLocation ); log("Box2DView::onTouchBegan, pos: %f,%f -> %f,%f", touchLocation.x, touchLocation.y, nodePosition.x, nodePosition.y); - return m_test->MouseDown(b2Vec2(nodePosition.x,nodePosition.y)); + return m_test->MouseDown(b2Vec2(nodePosition.x,nodePosition.y)); } void Box2DView::onTouchMoved(Touch* touch, Event* event) @@ -262,6 +269,18 @@ void Box2DView::onTouchEnded(Touch* touch, Event* event) m_test->MouseUp(b2Vec2(nodePosition.x,nodePosition.y)); } +void Box2DView::onKeyPressed(EventKeyboard::KeyCode code, Event* event) +{ + log("Box2dView:onKeyPressed, keycode: %d", code); + m_test->Keyboard(static_cast(code)); +} + +void Box2DView::onKeyReleased(EventKeyboard::KeyCode code, Event* event) +{ + log("onKeyReleased, keycode: %d", code); + m_test->KeyboardUp(static_cast(code)); +} + // void Box2DView::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration) // { // //// Only run for valid values diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h index b7c71823ef..4c73a975c2 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h +++ b/tests/cpp-tests/Classes/Box2DTestBed/Box2dView.h @@ -32,6 +32,7 @@ class Test; class Box2DView : public Layer { EventListenerTouchOneByOne* _touchListener; + EventListenerKeyboard* _keyboardListener; TestEntry* m_entry; Test* m_test; int m_entryID; @@ -47,6 +48,9 @@ public: bool onTouchBegan(Touch* touch, Event* event); void onTouchMoved(Touch* touch, Event* event); void onTouchEnded(Touch* touch, Event* event); + + void onKeyPressed(EventKeyboard::KeyCode code, Event* event); + void onKeyReleased(EventKeyboard::KeyCode code, Event* event); //virtual void accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration); static Box2DView* viewWithEntryID(int entryId); diff --git a/tests/cpp-tests/Classes/Box2DTestBed/GLES-Render.cpp b/tests/cpp-tests/Classes/Box2DTestBed/GLES-Render.cpp index b904ee6e87..e39dafb36e 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/GLES-Render.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/GLES-Render.cpp @@ -242,9 +242,9 @@ void GLESDebugDraw::DrawAABB(b2AABB* aabb, const b2Color& color) }; glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, glVertices); - glDrawArrays(GL_LINE_LOOP, 0, 8); + glDrawArrays(GL_LINE_LOOP, 0, 4); - CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,8); + CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,4); CHECK_GL_ERROR_DEBUG(); } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/TestEntries.cpp b/tests/cpp-tests/Classes/Box2DTestBed/TestEntries.cpp index 2d6f22f65c..57d437a92b 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/TestEntries.cpp +++ b/tests/cpp-tests/Classes/Box2DTestBed/TestEntries.cpp @@ -76,7 +76,7 @@ TestEntry g_testEntries[] = {"Convex Hull", ConvexHull::Create}, {"Apply Force", ApplyForce::Create}, {"Continuous Test", ContinuousTest::Create}, - {"Time of Impact", TimeOfImpact::Create}, + // {"Time of Impact", TimeOfImpact::Create}, {"Motor Joint", MotorJoint::Create}, {"One-Sided Platform", OneSidedPlatform::Create}, {"Mobile", Mobile::Create}, diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Tests/Mobile.h b/tests/cpp-tests/Classes/Box2DTestBed/Tests/Mobile.h index 9244a66d6b..d16e659379 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Tests/Mobile.h +++ b/tests/cpp-tests/Classes/Box2DTestBed/Tests/Mobile.h @@ -35,7 +35,7 @@ public: // Create ground body. { b2BodyDef bodyDef; - bodyDef.position.Set(0.0f, 20.0f); + bodyDef.position.Set(0.0f, 5.0f); ground = m_world->CreateBody(&bodyDef); } diff --git a/tests/cpp-tests/Classes/Box2DTestBed/Tests/MobileBalanced.h b/tests/cpp-tests/Classes/Box2DTestBed/Tests/MobileBalanced.h index 50e852e331..ea4784190b 100644 --- a/tests/cpp-tests/Classes/Box2DTestBed/Tests/MobileBalanced.h +++ b/tests/cpp-tests/Classes/Box2DTestBed/Tests/MobileBalanced.h @@ -35,7 +35,7 @@ public: // Create ground body. { b2BodyDef bodyDef; - bodyDef.position.Set(0.0f, 20.0f); + bodyDef.position.Set(0.0f, 5.0f); ground = m_world->CreateBody(&bodyDef); }