mirror of https://github.com/axmolengine/axmol.git
Merge pull request #6065 from boyu0/3.0rc1_test
fix box2dbed dynamic tree test draw.
This commit is contained in:
commit
313108af82
|
@ -188,6 +188,12 @@ bool Box2DView::initWithEntryID(int entryId)
|
||||||
_eventDispatcher->addEventListenerWithFixedPriority(listener, -10);
|
_eventDispatcher->addEventListenerWithFixedPriority(listener, -10);
|
||||||
_touchListener = listener;
|
_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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,6 +228,7 @@ Box2DView::~Box2DView()
|
||||||
{
|
{
|
||||||
// Removes Touch Event Listener
|
// Removes Touch Event Listener
|
||||||
_eventDispatcher->removeEventListener(_touchListener);
|
_eventDispatcher->removeEventListener(_touchListener);
|
||||||
|
_eventDispatcher->removeEventListener(_keyboardListener);
|
||||||
delete m_test;
|
delete m_test;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -262,6 +269,18 @@ void Box2DView::onTouchEnded(Touch* touch, Event* event)
|
||||||
m_test->MouseUp(b2Vec2(nodePosition.x,nodePosition.y));
|
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)
|
// void Box2DView::accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration)
|
||||||
// {
|
// {
|
||||||
// //// Only run for valid values
|
// //// Only run for valid values
|
||||||
|
|
|
@ -32,6 +32,7 @@ class Test;
|
||||||
class Box2DView : public Layer
|
class Box2DView : public Layer
|
||||||
{
|
{
|
||||||
EventListenerTouchOneByOne* _touchListener;
|
EventListenerTouchOneByOne* _touchListener;
|
||||||
|
EventListenerKeyboard* _keyboardListener;
|
||||||
TestEntry* m_entry;
|
TestEntry* m_entry;
|
||||||
Test* m_test;
|
Test* m_test;
|
||||||
int m_entryID;
|
int m_entryID;
|
||||||
|
@ -47,6 +48,9 @@ public:
|
||||||
bool onTouchBegan(Touch* touch, Event* event);
|
bool onTouchBegan(Touch* touch, Event* event);
|
||||||
void onTouchMoved(Touch* touch, Event* event);
|
void onTouchMoved(Touch* touch, Event* event);
|
||||||
void onTouchEnded(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);
|
//virtual void accelerometer(UIAccelerometer* accelerometer, Acceleration* acceleration);
|
||||||
|
|
||||||
static Box2DView* viewWithEntryID(int entryId);
|
static Box2DView* viewWithEntryID(int entryId);
|
||||||
|
|
|
@ -242,9 +242,9 @@ void GLESDebugDraw::DrawAABB(b2AABB* aabb, const b2Color& color)
|
||||||
};
|
};
|
||||||
|
|
||||||
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, glVertices);
|
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();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ TestEntry g_testEntries[] =
|
||||||
{"Convex Hull", ConvexHull::Create},
|
{"Convex Hull", ConvexHull::Create},
|
||||||
{"Apply Force", ApplyForce::Create},
|
{"Apply Force", ApplyForce::Create},
|
||||||
{"Continuous Test", ContinuousTest::Create},
|
{"Continuous Test", ContinuousTest::Create},
|
||||||
{"Time of Impact", TimeOfImpact::Create},
|
// {"Time of Impact", TimeOfImpact::Create},
|
||||||
{"Motor Joint", MotorJoint::Create},
|
{"Motor Joint", MotorJoint::Create},
|
||||||
{"One-Sided Platform", OneSidedPlatform::Create},
|
{"One-Sided Platform", OneSidedPlatform::Create},
|
||||||
{"Mobile", Mobile::Create},
|
{"Mobile", Mobile::Create},
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
// Create ground body.
|
// Create ground body.
|
||||||
{
|
{
|
||||||
b2BodyDef bodyDef;
|
b2BodyDef bodyDef;
|
||||||
bodyDef.position.Set(0.0f, 20.0f);
|
bodyDef.position.Set(0.0f, 5.0f);
|
||||||
ground = m_world->CreateBody(&bodyDef);
|
ground = m_world->CreateBody(&bodyDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
// Create ground body.
|
// Create ground body.
|
||||||
{
|
{
|
||||||
b2BodyDef bodyDef;
|
b2BodyDef bodyDef;
|
||||||
bodyDef.position.Set(0.0f, 20.0f);
|
bodyDef.position.Set(0.0f, 5.0f);
|
||||||
ground = m_world->CreateBody(&bodyDef);
|
ground = m_world->CreateBody(&bodyDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue