Merge pull request #6065 from boyu0/3.0rc1_test

fix box2dbed dynamic tree test draw.
This commit is contained in:
James Chen 2014-03-31 14:38:00 +08:00
commit 313108af82
6 changed files with 29 additions and 6 deletions

View File

@ -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<unsigned char>(code));
}
void Box2DView::onKeyReleased(EventKeyboard::KeyCode code, Event* event)
{
log("onKeyReleased, keycode: %d", code);
m_test->KeyboardUp(static_cast<unsigned char>(code));
}
// void Box2DView::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration)
// {
// //// Only run for valid values

View File

@ -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);

View File

@ -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();
}

View File

@ -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},

View File

@ -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);
}

View File

@ -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);
}