mirror of https://github.com/axmolengine/axmol.git
closed #5537: add test case
This commit is contained in:
parent
a3f32cf894
commit
1df80a8ce4
|
@ -21,6 +21,7 @@ namespace
|
|||
CL(PhysicsPositionRotationTest),
|
||||
CL(PhysicsSetGravityEnableTest),
|
||||
CL(Bug5482),
|
||||
CL(PhysicsFixedUpdate),
|
||||
#else
|
||||
CL(PhysicsDemoDisabled),
|
||||
#endif
|
||||
|
@ -1725,4 +1726,60 @@ std::string Bug5482::subtitle() const
|
|||
return "change physics body to the other.";
|
||||
}
|
||||
|
||||
void PhysicsFixedUpdate::onEnter()
|
||||
{
|
||||
PhysicsDemo::onEnter();
|
||||
|
||||
_scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
|
||||
_scene->getPhysicsWorld()->setGravity(Point::ZERO);
|
||||
|
||||
// wall
|
||||
auto wall = Node::create();
|
||||
wall->setPhysicsBody(PhysicsBody::createEdgeBox(VisibleRect::getVisibleRect().size, PhysicsMaterial(0.1f, 1, 0.0f)));
|
||||
wall->setPosition(VisibleRect::center());
|
||||
this->addChild(wall);
|
||||
|
||||
addBall();
|
||||
|
||||
scheduleOnce(schedule_selector(PhysicsFixedUpdate::updateStart), 2);
|
||||
}
|
||||
|
||||
void PhysicsFixedUpdate::addBall()
|
||||
{
|
||||
auto ball = Sprite::create("Images/ball.png");
|
||||
ball->setPosition(100, 100);
|
||||
ball->setPhysicsBody(PhysicsBody::createCircle(ball->getContentSize().width/2, PhysicsMaterial(0.1f, 1, 0.0f)));
|
||||
ball->getPhysicsBody()->setTag(DRAG_BODYS_TAG);
|
||||
ball->getPhysicsBody()->setVelocity(Point(1000, 20));
|
||||
this->addChild(ball);
|
||||
}
|
||||
|
||||
void PhysicsFixedUpdate::updateStart(float delta)
|
||||
{
|
||||
addBall();
|
||||
|
||||
_scene->getPhysicsWorld()->setAutoStep(false);
|
||||
scheduleUpdate();
|
||||
}
|
||||
|
||||
void PhysicsFixedUpdate::update(float delta)
|
||||
{
|
||||
|
||||
// use fixed time and calculate 3 times per frame makes physics simulate more precisely.
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
_scene->getPhysicsWorld()->step(1/180.0f);
|
||||
}
|
||||
}
|
||||
|
||||
std::string PhysicsFixedUpdate::title() const
|
||||
{
|
||||
return "Fixed Update Test";
|
||||
}
|
||||
|
||||
std::string PhysicsFixedUpdate::subtitle() const
|
||||
{
|
||||
return "The secend ball should not run across the wall";
|
||||
}
|
||||
|
||||
#endif // ifndef CC_USE_PHYSICS
|
||||
|
|
|
@ -255,6 +255,18 @@ private:
|
|||
bool _bodyInA;
|
||||
};
|
||||
|
||||
class PhysicsFixedUpdate : public PhysicsDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(PhysicsFixedUpdate);
|
||||
void onEnter() override;
|
||||
void updateStart(float delta);
|
||||
void addBall();
|
||||
virtual void update(float delta) override;
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue