mirror of https://github.com/axmolengine/axmol.git
Merge pull request #10238 from Dhilan007/v3-scale9sprite-fix
Fixed Scale9Sprite can't run move/scale/rotation action in physics scene
This commit is contained in:
commit
b233d6928e
|
@ -126,6 +126,7 @@ Node::Node(void)
|
||||||
, _physicsScaleStartY(1.0f)
|
, _physicsScaleStartY(1.0f)
|
||||||
, _physicsRotation(0.0f)
|
, _physicsRotation(0.0f)
|
||||||
, _physicsTransformDirty(true)
|
, _physicsTransformDirty(true)
|
||||||
|
, _updateTransformFromPhysics(true)
|
||||||
#endif
|
#endif
|
||||||
, _displayedOpacity(255)
|
, _displayedOpacity(255)
|
||||||
, _realOpacity(255)
|
, _realOpacity(255)
|
||||||
|
@ -330,6 +331,11 @@ void Node::setRotation(float rotation)
|
||||||
|
|
||||||
_rotationZ_X = _rotationZ_Y = rotation;
|
_rotationZ_X = _rotationZ_Y = rotation;
|
||||||
_transformUpdated = _transformDirty = _inverseDirty = true;
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
||||||
|
#if CC_USE_PHYSICS
|
||||||
|
if (_physicsBody && _physicsBody->getWorld()) {
|
||||||
|
_physicsBody->getWorld()->_updateBodyTransform = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
updateRotationQuat();
|
updateRotationQuat();
|
||||||
}
|
}
|
||||||
|
@ -466,6 +472,11 @@ void Node::setScale(float scale)
|
||||||
|
|
||||||
_scaleX = _scaleY = _scaleZ = scale;
|
_scaleX = _scaleY = _scaleZ = scale;
|
||||||
_transformUpdated = _transformDirty = _inverseDirty = true;
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
||||||
|
#if CC_USE_PHYSICS
|
||||||
|
if (_physicsBody && _physicsBody->getWorld()) {
|
||||||
|
_physicsBody->getWorld()->_updateBodyTransform = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// scaleX getter
|
/// scaleX getter
|
||||||
|
@ -483,6 +494,11 @@ void Node::setScale(float scaleX,float scaleY)
|
||||||
_scaleX = scaleX;
|
_scaleX = scaleX;
|
||||||
_scaleY = scaleY;
|
_scaleY = scaleY;
|
||||||
_transformUpdated = _transformDirty = _inverseDirty = true;
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
||||||
|
#if CC_USE_PHYSICS
|
||||||
|
if (_physicsBody && _physicsBody->getWorld()) {
|
||||||
|
_physicsBody->getWorld()->_updateBodyTransform = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// scaleX setter
|
/// scaleX setter
|
||||||
|
@ -493,6 +509,11 @@ void Node::setScaleX(float scaleX)
|
||||||
|
|
||||||
_scaleX = scaleX;
|
_scaleX = scaleX;
|
||||||
_transformUpdated = _transformDirty = _inverseDirty = true;
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
||||||
|
#if CC_USE_PHYSICS
|
||||||
|
if (_physicsBody && _physicsBody->getWorld()) {
|
||||||
|
_physicsBody->getWorld()->_updateBodyTransform = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// scaleY getter
|
/// scaleY getter
|
||||||
|
@ -532,6 +553,11 @@ void Node::setScaleY(float scaleY)
|
||||||
|
|
||||||
_scaleY = scaleY;
|
_scaleY = scaleY;
|
||||||
_transformUpdated = _transformDirty = _inverseDirty = true;
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
||||||
|
#if CC_USE_PHYSICS
|
||||||
|
if (_physicsBody && _physicsBody->getWorld()) {
|
||||||
|
_physicsBody->getWorld()->_updateBodyTransform = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -563,6 +589,11 @@ void Node::setPosition(float x, float y)
|
||||||
|
|
||||||
_transformUpdated = _transformDirty = _inverseDirty = true;
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
||||||
_usingNormalizedPosition = false;
|
_usingNormalizedPosition = false;
|
||||||
|
#if CC_USE_PHYSICS
|
||||||
|
if (_physicsBody && _physicsBody->getWorld()) {
|
||||||
|
_physicsBody->getWorld()->_updateBodyTransform = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::setPosition3D(const Vec3& position)
|
void Node::setPosition3D(const Vec3& position)
|
||||||
|
@ -627,6 +658,11 @@ void Node::setNormalizedPosition(const Vec2& position)
|
||||||
_usingNormalizedPosition = true;
|
_usingNormalizedPosition = true;
|
||||||
_normalizedPositionDirty = true;
|
_normalizedPositionDirty = true;
|
||||||
_transformUpdated = _transformDirty = _inverseDirty = true;
|
_transformUpdated = _transformDirty = _inverseDirty = true;
|
||||||
|
#if CC_USE_PHYSICS
|
||||||
|
if (_physicsBody && _physicsBody->getWorld()) {
|
||||||
|
_physicsBody->getWorld()->_updateBodyTransform = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Node::getChildrenCount() const
|
ssize_t Node::getChildrenCount() const
|
||||||
|
@ -1267,8 +1303,15 @@ uint32_t Node::processParentFlags(const Mat4& parentTransform, uint32_t parentFl
|
||||||
if(flags & FLAGS_DIRTY_MASK)
|
if(flags & FLAGS_DIRTY_MASK)
|
||||||
_modelViewTransform = this->transform(parentTransform);
|
_modelViewTransform = this->transform(parentTransform);
|
||||||
|
|
||||||
|
#if CC_USE_PHYSICS
|
||||||
|
if (_updateTransformFromPhysics) {
|
||||||
_transformUpdated = false;
|
_transformUpdated = false;
|
||||||
_contentSizeDirty = false;
|
_contentSizeDirty = false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
_transformUpdated = false;
|
||||||
|
_contentSizeDirty = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
@ -2017,7 +2060,7 @@ void Node::setPhysicsBody(PhysicsBody* body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::updatePhysicsBodyTransform(Scene* scene, const Mat4& parentTransform, uint32_t parentFlags, float parentScaleX, float parentScaleY)
|
void Node::updatePhysicsBodyTransform(const Mat4& parentTransform, uint32_t parentFlags, float parentScaleX, float parentScaleY)
|
||||||
{
|
{
|
||||||
_updateTransformFromPhysics = false;
|
_updateTransformFromPhysics = false;
|
||||||
auto flags = processParentFlags(parentTransform, parentFlags);
|
auto flags = processParentFlags(parentTransform, parentFlags);
|
||||||
|
@ -2042,7 +2085,7 @@ void Node::updatePhysicsBodyTransform(Scene* scene, const Mat4& parentTransform,
|
||||||
|
|
||||||
for (auto node : _children)
|
for (auto node : _children)
|
||||||
{
|
{
|
||||||
node->updatePhysicsBodyTransform(scene, _modelViewTransform, flags, scaleX, scaleY);
|
node->updatePhysicsBodyTransform(_modelViewTransform, flags, scaleX, scaleY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1543,7 +1543,7 @@ public:
|
||||||
|
|
||||||
void updateTransformFromPhysics(const Mat4& parentTransform, uint32_t parentFlags);
|
void updateTransformFromPhysics(const Mat4& parentTransform, uint32_t parentFlags);
|
||||||
|
|
||||||
virtual void updatePhysicsBodyTransform(Scene* scene, const Mat4& parentTransform, uint32_t parentFlags, float parentScaleX, float parentScaleY);
|
virtual void updatePhysicsBodyTransform(const Mat4& parentTransform, uint32_t parentFlags, float parentScaleX, float parentScaleY);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// overrides
|
// overrides
|
||||||
|
|
|
@ -300,6 +300,12 @@ void Director::drawScene()
|
||||||
_runningScene->render(_renderer);
|
_runningScene->render(_renderer);
|
||||||
|
|
||||||
_eventDispatcher->dispatchEvent(_eventAfterVisit);
|
_eventDispatcher->dispatchEvent(_eventAfterVisit);
|
||||||
|
#if CC_USE_PHYSICS
|
||||||
|
if(physicsWorld)
|
||||||
|
{
|
||||||
|
physicsWorld->_updateBodyTransform = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw the notifications node
|
// draw the notifications node
|
||||||
|
|
|
@ -334,7 +334,7 @@ void PhysicsWorld::rayCast(PhysicsRayCastCallbackFunc func, const Vec2& point1,
|
||||||
{
|
{
|
||||||
if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty())
|
if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty())
|
||||||
{
|
{
|
||||||
_scene->updatePhysicsBodyTransform(_scene, _scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
|
_scene->updatePhysicsBodyTransform(_scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
|
||||||
updateBodies();
|
updateBodies();
|
||||||
}
|
}
|
||||||
RayCastCallbackInfo info = { this, func, point1, point2, data };
|
RayCastCallbackInfo info = { this, func, point1, point2, data };
|
||||||
|
@ -358,7 +358,7 @@ void PhysicsWorld::queryRect(PhysicsQueryRectCallbackFunc func, const Rect& rect
|
||||||
{
|
{
|
||||||
if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty())
|
if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty())
|
||||||
{
|
{
|
||||||
_scene->updatePhysicsBodyTransform(_scene, _scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
|
_scene->updatePhysicsBodyTransform(_scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
|
||||||
updateBodies();
|
updateBodies();
|
||||||
}
|
}
|
||||||
RectQueryCallbackInfo info = {this, func, data};
|
RectQueryCallbackInfo info = {this, func, data};
|
||||||
|
@ -381,7 +381,7 @@ void PhysicsWorld::queryPoint(PhysicsQueryPointCallbackFunc func, const Vec2& po
|
||||||
{
|
{
|
||||||
if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty())
|
if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty())
|
||||||
{
|
{
|
||||||
_scene->updatePhysicsBodyTransform(_scene, _scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
|
_scene->updatePhysicsBodyTransform(_scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
|
||||||
updateBodies();
|
updateBodies();
|
||||||
}
|
}
|
||||||
PointQueryCallbackInfo info = {this, func, data};
|
PointQueryCallbackInfo info = {this, func, data};
|
||||||
|
@ -823,9 +823,13 @@ void PhysicsWorld::update(float delta, bool userCall/* = false*/)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_scene->updatePhysicsBodyTransform(_scene, _scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
|
if(_updateBodyTransform || !_delayAddBodies.empty())
|
||||||
|
{
|
||||||
if (!_delayAddBodies.empty() || !_delayRemoveBodies.empty())
|
_scene->updatePhysicsBodyTransform(_scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
|
||||||
|
updateBodies();
|
||||||
|
_updateBodyTransform = false;
|
||||||
|
}
|
||||||
|
else if (!_delayRemoveBodies.empty())
|
||||||
{
|
{
|
||||||
updateBodies();
|
updateBodies();
|
||||||
}
|
}
|
||||||
|
@ -880,6 +884,7 @@ PhysicsWorld::PhysicsWorld()
|
||||||
, _autoStep(true)
|
, _autoStep(true)
|
||||||
, _debugDraw(nullptr)
|
, _debugDraw(nullptr)
|
||||||
, _debugDrawMask(DEBUGDRAW_NONE)
|
, _debugDrawMask(DEBUGDRAW_NONE)
|
||||||
|
, _updateBodyTransform(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,6 +204,7 @@ protected:
|
||||||
int _substeps;
|
int _substeps;
|
||||||
cpSpace* _cpSpace;
|
cpSpace* _cpSpace;
|
||||||
|
|
||||||
|
bool _updateBodyTransform;
|
||||||
Vector<PhysicsBody*> _bodies;
|
Vector<PhysicsBody*> _bodies;
|
||||||
std::list<PhysicsJoint*> _joints;
|
std::list<PhysicsJoint*> _joints;
|
||||||
Scene* _scene;
|
Scene* _scene;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "PhysicsTest.h"
|
#include "PhysicsTest.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "../testResource.h"
|
#include "../testResource.h"
|
||||||
|
#include "ui/CocosGUI.h"
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -23,6 +24,7 @@ namespace
|
||||||
CL(Bug5482),
|
CL(Bug5482),
|
||||||
CL(PhysicsFixedUpdate),
|
CL(PhysicsFixedUpdate),
|
||||||
CL(PhysicsTransformTest),
|
CL(PhysicsTransformTest),
|
||||||
|
CL(PhysicsIssue9959)
|
||||||
#else
|
#else
|
||||||
CL(PhysicsDemoDisabled),
|
CL(PhysicsDemoDisabled),
|
||||||
#endif
|
#endif
|
||||||
|
@ -1865,4 +1867,37 @@ std::string PhysicsTransformTest::title() const
|
||||||
return "Physics transform test";
|
return "Physics transform test";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysicsIssue9959::onEnter()
|
||||||
|
{
|
||||||
|
PhysicsDemo::onEnter();
|
||||||
|
|
||||||
|
auto origin = Director::getInstance()->getVisibleOrigin();
|
||||||
|
auto visibleSize = Director::getInstance()->getVisibleSize();
|
||||||
|
|
||||||
|
auto scale9Sprite1 = ui::Scale9Sprite::create("Images/ball.png");
|
||||||
|
scale9Sprite1->setPosition(origin + visibleSize/2);
|
||||||
|
addChild(scale9Sprite1);
|
||||||
|
scale9Sprite1->runAction(RepeatForever::create(Sequence::create(MoveBy::create(2.0f, Vec2(100.0f,0.0f)), MoveBy::create(2.0f, Vec2(-100.0f, 0.0f)), NULL)));
|
||||||
|
|
||||||
|
auto scale9Sprite2 = ui::Scale9Sprite::create("Images/ball.png");
|
||||||
|
scale9Sprite2->setPosition(origin + visibleSize/2 + Vec2(0.0f, 50.0f));
|
||||||
|
addChild(scale9Sprite2);
|
||||||
|
scale9Sprite2->runAction(RepeatForever::create(Sequence::create(ScaleTo::create(2.0f, 1.5f), ScaleTo::create(2.0f, 1.0f), NULL)));
|
||||||
|
|
||||||
|
auto scale9Sprite3 = ui::Scale9Sprite::create("Images/ball.png");
|
||||||
|
scale9Sprite3->setPosition(origin + visibleSize/2 + Vec2(0.0f, -50.0f));
|
||||||
|
addChild(scale9Sprite3);
|
||||||
|
scale9Sprite3->runAction(RepeatForever::create(RotateBy::create(2.0f, 360.0f)));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PhysicsIssue9959::title() const
|
||||||
|
{
|
||||||
|
return "Reorder issue #9959";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string PhysicsIssue9959::subtitle() const
|
||||||
|
{
|
||||||
|
return "Test Scale9Sprite run scale/move/rotation action in physics scene";
|
||||||
|
}
|
||||||
|
|
||||||
#endif // ifndef CC_USE_PHYSICS
|
#endif // ifndef CC_USE_PHYSICS
|
||||||
|
|
|
@ -278,5 +278,16 @@ public:
|
||||||
bool onTouchBegan(Touch* touch, Event* event);
|
bool onTouchBegan(Touch* touch, Event* event);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PhysicsIssue9959 : public PhysicsDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(PhysicsIssue9959);
|
||||||
|
|
||||||
|
void onEnter() override;
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue