PhysicsBody moved automatically when resume from background for android


#1

Follow the below steps:
1、Create a PhysicsBody.
// create physical world
auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setDebugDrawMask(cocos2d::PhysicsWorld::DEBUGDRAW_ALL);

// create edge
auto contentSize = this->getContentSize();
auto edge = Node::create();
edge->setPhysicsBody(PhysicsBody::createEdgeBox(contentSize));
edge->setPosition(contentSize.width / 2, contentSize.height / 2);
this->addChild(edge);
// create PhysicalBody
auto role = cocos2d::Sprite::create(“block.png”);
auto roleSize = role->getBoundingBox().size;
role->setPosition(contentSize.width / 2, roleSize.height / 2);
role->setPhysicsBody(PhysicsBody::createBox(roleSize));
this->addChild(role);、
2、Compile and generate apk file.
3、Running app on android device.
4、Press the Home button.
5、Launching the app again. The PhysicalBody will move automatically when resume from background.

cocos2d-x version is v3.0beta2.
The problems are the same on samusung note 2 and mi3。

Anyone can help me?
Looking forward to your replies.
Thanks.


HelloWorldScene.cpp.zip (1.0 KB)


Test.apk.zip (1522.2 KB)


#2

?