mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5325 from boyu0/iss3988_physics_setRotation_bug
closed #3988: fix bug Node::setRotation() moves opposite when node has a physics body.
This commit is contained in:
commit
8ede1607a2
|
@ -345,7 +345,7 @@ void PhysicsBody::setPosition(Point position)
|
||||||
|
|
||||||
void PhysicsBody::setRotation(float rotation)
|
void PhysicsBody::setRotation(float rotation)
|
||||||
{
|
{
|
||||||
cpBodySetAngle(_info->getBody(), PhysicsHelper::float2cpfloat(rotation * M_PI / 180.0f));
|
cpBodySetAngle(_info->getBody(), -PhysicsHelper::float2cpfloat(rotation * M_PI / 180.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
Point PhysicsBody::getPosition() const
|
Point PhysicsBody::getPosition() const
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace
|
||||||
CL(PhysicsDemoPump),
|
CL(PhysicsDemoPump),
|
||||||
CL(PhysicsDemoOneWayPlatform),
|
CL(PhysicsDemoOneWayPlatform),
|
||||||
CL(PhysicsDemoSlice),
|
CL(PhysicsDemoSlice),
|
||||||
|
CL(PhysicsDemoBug3988),
|
||||||
#else
|
#else
|
||||||
CL(PhysicsDemoDisabled),
|
CL(PhysicsDemoDisabled),
|
||||||
#endif
|
#endif
|
||||||
|
@ -1219,4 +1220,31 @@ std::string PhysicsDemoSlice::subtitle() const
|
||||||
return "click and drag to slice up the block";
|
return "click and drag to slice up the block";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PhysicsDemoBug3988::onEnter()
|
||||||
|
{
|
||||||
|
PhysicsDemo::onEnter();
|
||||||
|
_scene->toggleDebug();
|
||||||
|
_scene->getPhysicsWorld()->setGravity(Vect::ZERO);
|
||||||
|
|
||||||
|
auto ball = Sprite::create("Images/YellowSquare.png");
|
||||||
|
ball->setPosition(VisibleRect::center() - Point(100, 0));
|
||||||
|
ball->setRotation(30.0f);
|
||||||
|
this->addChild(ball);
|
||||||
|
|
||||||
|
auto physicsBall = makeBox(VisibleRect::center() + Point(100, 0), Size(100, 100));
|
||||||
|
physicsBall->setRotation(30.0f);
|
||||||
|
this->addChild(physicsBall);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PhysicsDemoBug3988::title() const
|
||||||
|
{
|
||||||
|
return "Bug3988";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PhysicsDemoBug3988::subtitle() const
|
||||||
|
{
|
||||||
|
return "All the Rectangles should have same rotation angle";
|
||||||
|
}
|
||||||
|
|
||||||
#endif // ifndef CC_USE_PHYSICS
|
#endif // ifndef CC_USE_PHYSICS
|
||||||
|
|
|
@ -184,5 +184,16 @@ private:
|
||||||
int _sliceTag;
|
int _sliceTag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PhysicsDemoBug3988 : public PhysicsDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(PhysicsDemoBug3988);
|
||||||
|
|
||||||
|
void onEnter() override;
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue