diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index c4362e57ff..165ce201bd 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -4cd02813dfcd14b7de3ccb157cd0f25b0bce9f37 \ No newline at end of file +54e971301f0ad11306c27cf6eba8eca695fb4f37 \ No newline at end of file diff --git a/cocos/2d/Android.mk b/cocos/2d/Android.mk index 9f5eba4108..5e49adf274 100644 --- a/cocos/2d/Android.mk +++ b/cocos/2d/Android.mk @@ -60,6 +60,7 @@ CCGLProgram.cpp \ ccGLStateCache.cpp \ CCGrabber.cpp \ CCGrid.cpp \ +CCNodeGrid.cpp \ CCIMEDispatcher.cpp \ CCLabel.cpp \ CCLabelAtlas.cpp \ diff --git a/cocos/2d/CCActionGrid.cpp b/cocos/2d/CCActionGrid.cpp index 87fc9c79a3..edd96ae0da 100644 --- a/cocos/2d/CCActionGrid.cpp +++ b/cocos/2d/CCActionGrid.cpp @@ -25,6 +25,7 @@ THE SOFTWARE. #include "CCActionGrid.h" #include "CCDirector.h" #include "CCGrid.h" +#include "CCNodeGrid.h" NS_CC_BEGIN // implementation of GridAction @@ -44,11 +45,11 @@ bool GridAction::initWithDuration(float duration, const Size& gridSize) void GridAction::startWithTarget(Node *target) { ActionInterval::startWithTarget(target); + cacheTargetAsGridNode(); GridBase *newgrid = this->getGrid(); - Node *t = _target; - GridBase *targetGrid = t->getGrid(); + GridBase *targetGrid = _gridNodeTarget->getGrid(); if (targetGrid && targetGrid->getReuseGrid() > 0) { @@ -69,11 +70,17 @@ void GridAction::startWithTarget(Node *target) targetGrid->setActive(false); } - t->setGrid(newgrid); - t->getGrid()->setActive(true); + _gridNodeTarget->setGrid(newgrid); + _gridNodeTarget->getGrid()->setActive(true); } } +void GridAction::cacheTargetAsGridNode() +{ + _gridNodeTarget = dynamic_cast (_target); + CCASSERT(_gridNodeTarget, "GridActions can only used on NodeGrid"); +} + GridAction* GridAction::reverse() const { // FIXME: This conversion isn't safe. @@ -97,19 +104,19 @@ GridBase* Grid3DAction::getGrid() Vertex3F Grid3DAction::getVertex(const Point& position) const { - Grid3D *g = (Grid3D*)_target->getGrid(); + Grid3D *g = (Grid3D*)_gridNodeTarget->getGrid(); return g->getVertex(position); } Vertex3F Grid3DAction::getOriginalVertex(const Point& position) const { - Grid3D *g = (Grid3D*)_target->getGrid(); + Grid3D *g = (Grid3D*)_gridNodeTarget->getGrid(); return g->getOriginalVertex(position); } void Grid3DAction::setVertex(const Point& position, const Vertex3F& vertex) { - Grid3D *g = (Grid3D*)_target->getGrid(); + Grid3D *g = (Grid3D*)_gridNodeTarget->getGrid(); g->setVertex(position, vertex); } @@ -122,19 +129,19 @@ GridBase* TiledGrid3DAction::getGrid(void) Quad3 TiledGrid3DAction::getTile(const Point& pos) const { - TiledGrid3D *g = (TiledGrid3D*)_target->getGrid(); + TiledGrid3D *g = (TiledGrid3D*)_gridNodeTarget->getGrid(); return g->getTile(pos); } Quad3 TiledGrid3DAction::getOriginalTile(const Point& pos) const { - TiledGrid3D *g = (TiledGrid3D*)_target->getGrid(); + TiledGrid3D *g = (TiledGrid3D*)_gridNodeTarget->getGrid(); return g->getOriginalTile(pos); } void TiledGrid3DAction::setTile(const Point& pos, const Quad3& coords) { - TiledGrid3D *g = (TiledGrid3D*)_target->getGrid(); + TiledGrid3D *g = (TiledGrid3D*)_gridNodeTarget->getGrid(); return g->setTile(pos, coords); } @@ -345,14 +352,20 @@ DeccelAmplitude* DeccelAmplitude::reverse() const void StopGrid::startWithTarget(Node *target) { ActionInstant::startWithTarget(target); - - GridBase *grid = _target->getGrid(); + cacheTargetAsGridNode(); + GridBase *grid = _gridNodeTarget->getGrid(); if (grid && grid->isActive()) { grid->setActive(false); } } +void StopGrid::cacheTargetAsGridNode() +{ + _gridNodeTarget = dynamic_cast (_target); + CCASSERT(_gridNodeTarget, "GridActions can only used on NodeGrid"); +} + StopGrid* StopGrid::create() { StopGrid* pAction = new StopGrid(); @@ -402,13 +415,20 @@ bool ReuseGrid::initWithTimes(int times) void ReuseGrid::startWithTarget(Node *target) { ActionInstant::startWithTarget(target); + cacheTargetAsGridNode(); - if (_target->getGrid() && _target->getGrid()->isActive()) + if (_gridNodeTarget->getGrid() && _gridNodeTarget->getGrid()->isActive()) { - _target->getGrid()->setReuseGrid(_target->getGrid()->getReuseGrid() + _times); + _gridNodeTarget->getGrid()->setReuseGrid(_gridNodeTarget->getGrid()->getReuseGrid() + _times); } } +void ReuseGrid::cacheTargetAsGridNode() +{ + _gridNodeTarget = dynamic_cast (_target); + CCASSERT(_gridNodeTarget, "GridActions can only used on NodeGrid"); +} + ReuseGrid* ReuseGrid::clone() const { return ReuseGrid::create(_times); diff --git a/cocos/2d/CCActionGrid.h b/cocos/2d/CCActionGrid.h index b0104cc36a..b3981b42a8 100644 --- a/cocos/2d/CCActionGrid.h +++ b/cocos/2d/CCActionGrid.h @@ -31,6 +31,7 @@ THE SOFTWARE. NS_CC_BEGIN class GridBase; +class NodeGrid; /** * @addtogroup actions @@ -57,6 +58,10 @@ protected: bool initWithDuration(float duration, const Size& gridSize); Size _gridSize; + + NodeGrid* _gridNodeTarget; + + void cacheTargetAsGridNode(); private: CC_DISALLOW_COPY_AND_ASSIGN(GridAction); @@ -264,6 +269,10 @@ public: protected: StopGrid() {} virtual ~StopGrid() {} + + NodeGrid* _gridNodeTarget; + + void cacheTargetAsGridNode(); private: CC_DISALLOW_COPY_AND_ASSIGN(StopGrid); @@ -286,7 +295,11 @@ protected: virtual ~ReuseGrid() {} /** initializes an action with the number of times that the current grid will be reused */ bool initWithTimes(int times); - + + NodeGrid* _gridNodeTarget; + + void cacheTargetAsGridNode(); + int _times; private: diff --git a/cocos/2d/CCActionTiledGrid.cpp b/cocos/2d/CCActionTiledGrid.cpp index 8d2412a289..973634ace8 100644 --- a/cocos/2d/CCActionTiledGrid.cpp +++ b/cocos/2d/CCActionTiledGrid.cpp @@ -26,6 +26,7 @@ THE SOFTWARE. #include "CCDirector.h" #include "ccMacros.h" #include "CCGrid.h" +#include "CCNodeGrid.h" #include NS_CC_BEGIN @@ -279,7 +280,7 @@ void ShuffleTiles::placeTile(const Point& pos, Tile *t) { Quad3 coords = getOriginalTile(pos); - Point step = _target->getGrid()->getStep(); + Point step = _gridNodeTarget->getGrid()->getStep(); coords.bl.x += (int)(t->position.x * step.x); coords.bl.y += (int)(t->position.y * step.y); @@ -408,7 +409,7 @@ void FadeOutTRTiles::turnOffTile(const Point& pos) void FadeOutTRTiles::transformTile(const Point& pos, float distance) { Quad3 coords = getOriginalTile(pos); - Point step = _target->getGrid()->getStep(); + Point step = _gridNodeTarget->getGrid()->getStep(); coords.bl.x += (step.x / 2) * (1.0f - distance); coords.bl.y += (step.y / 2) * (1.0f - distance); @@ -535,7 +536,7 @@ float FadeOutUpTiles::testFunc(const Size& pos, float time) void FadeOutUpTiles::transformTile(const Point& pos, float distance) { Quad3 coords = getOriginalTile(pos); - Point step = _target->getGrid()->getStep(); + Point step = _gridNodeTarget->getGrid()->getStep(); coords.bl.y += (step.y / 2) * (1.0f - distance); coords.br.y += (step.y / 2) * (1.0f - distance); diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 18922971c1..f04d6933da 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -109,7 +109,6 @@ Node::Node(void) , _camera(nullptr) // children (lazy allocs) // lazy alloc -, _grid(nullptr) , _ZOrder(0) , _parent(nullptr) // "whole screen" objects. like Scenes and Layers, should set _ignoreAnchorPointForPosition to true @@ -171,7 +170,6 @@ Node::~Node() // attributes CC_SAFE_RELEASE(_camera); - CC_SAFE_RELEASE(_grid); CC_SAFE_RELEASE(_shaderProgram); CC_SAFE_RELEASE(_userObject); @@ -415,15 +413,6 @@ Camera* Node::getCamera() return _camera; } -/// grid setter -void Node::setGrid(GridBase* grid) -{ - CC_SAFE_RETAIN(grid); - CC_SAFE_RELEASE(_grid); - _grid = grid; -} - - /// isVisible getter bool Node::isVisible() const { @@ -823,11 +812,6 @@ void Node::visit() kmGLPushMatrix(); - if (_grid && _grid->isActive()) - { - _grid->beforeDraw(); - } - this->transform(); int i = 0; @@ -857,11 +841,6 @@ void Node::visit() // reset for next frame _orderOfArrival = 0; - - if (_grid && _grid->isActive()) - { - _grid->afterDraw(this); - } kmGLPopMatrix(); } @@ -888,24 +867,9 @@ void Node::transform() kmGLMultMatrix( &transfrom4x4 ); - // saves the MV matrix kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewTransform); - - // XXX: Expensive calls. Camera should be integrated into the cached affine matrix - if ( _camera != nullptr && !(_grid != nullptr && _grid->isActive()) ) - { - bool translate = (_anchorPointInPoints.x != 0.0f || _anchorPointInPoints.y != 0.0f); - - if( translate ) - kmGLTranslatef(RENDER_IN_SUBPIXEL(_anchorPointInPoints.x), RENDER_IN_SUBPIXEL(_anchorPointInPoints.y), 0 ); - - _camera->locate(); - - if( translate ) - kmGLTranslatef(RENDER_IN_SUBPIXEL(-_anchorPointInPoints.x), RENDER_IN_SUBPIXEL(-_anchorPointInPoints.y), 0 ); - } } diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 2b1b78a890..bd4ba41253 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -702,34 +702,7 @@ public: virtual void sortAllChildren(); /// @} end of Children and Parent - - - - /// @{ - /// @name Grid object for effects - - /** - * Returns a grid object that is used when applying effects - * - * @return A Grid object that is used when applying effects - * @js NA - */ - virtual GridBase* getGrid() { return _grid; } - /** - * @js NA - */ - virtual const GridBase* getGrid() const { return _grid; } - - /** - * Changes a grid object that is used when applying effects - * - * @param grid A Grid object that is used when applying effects - */ - virtual void setGrid(GridBase *grid); - - /// @} end of Grid - - + /// @{ /// @name Tag & User data @@ -1466,8 +1439,6 @@ protected: Camera *_camera; ///< a camera - GridBase *_grid; ///< a grid - int _ZOrder; ///< z-order value that affects the draw order Vector _children; ///< array of children nodes diff --git a/cocos/2d/CCNodeGrid.cpp b/cocos/2d/CCNodeGrid.cpp new file mode 100644 index 0000000000..a892e5bd59 --- /dev/null +++ b/cocos/2d/CCNodeGrid.cpp @@ -0,0 +1,160 @@ + +#include "CCNodeGrid.h" +#include "CCGrid.h" + +#include "CCGroupCommand.h" +#include "CCRenderer.h" +#include "CCCustomCommand.h" + + +NS_CC_BEGIN + +NodeGrid* NodeGrid::create() +{ + NodeGrid * ret = new NodeGrid(); + if (ret && ret->init()) + { + ret->autorelease(); + } + else + { + CC_SAFE_DELETE(ret); + } + return ret; +} + +NodeGrid::NodeGrid() +: _nodeGrid(nullptr) +, _gridTarget(nullptr) +{ + +} + +void NodeGrid::setTarget(Node* target) +{ + CC_SAFE_RELEASE(_gridTarget); + CC_SAFE_RETAIN(target); + _gridTarget = target; +} + +NodeGrid::~NodeGrid() +{ + CC_SAFE_RELEASE(_nodeGrid); + CC_SAFE_RELEASE(_gridTarget); +} + +bool NodeGrid::init() +{ + return Node::init(); +} + +void NodeGrid::onGridBeginDraw() +{ + if (_nodeGrid && _nodeGrid->isActive()) + { + _nodeGrid->beforeDraw(); + } +} + +void NodeGrid::onGridEndDraw() +{ + if(_nodeGrid && _nodeGrid->isActive()) + { + _nodeGrid->afterDraw(this); + } +} + +void NodeGrid::visit() +{ + // quick return if not visible. children won't be drawn. + if (!_visible) + { + return; + } + + Renderer* renderer = Director::getInstance()->getRenderer(); + + GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand(); + groupCommand->init(0,_vertexZ); + renderer->addCommand(groupCommand); + + renderer->pushGroup(groupCommand->getRenderQueueID()); + + kmGLPushMatrix(); + Director::Projection beforeProjectionType; + if(_nodeGrid && _nodeGrid->isActive()) + { + beforeProjectionType = Director::getInstance()->getProjection(); + _nodeGrid->set2DProjection(); + } + + kmGLGetMatrix(KM_GL_MODELVIEW, &_cachedMVmat); + + CustomCommand* gridBeginCmd = CustomCommand::getCommandPool().generateCommand(); + gridBeginCmd->init(0,_vertexZ); + gridBeginCmd->func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this); + renderer->addCommand(gridBeginCmd); + + this->transform(); + + if(_gridTarget) + { + _gridTarget->visit(); + } + + int i = 0; + + if(!_children.empty()) + { + sortAllChildren(); + // draw children zOrder < 0 + for( ; i < _children.size(); i++ ) + { + auto node = _children.at(i); + + if ( node && node->getZOrder() < 0 ) + node->visit(); + else + break; + } + // self draw,currently we have nothing to draw on NodeGrid, so there is no need to add render command + this->draw(); + + // Uses std::for_each to improve performance. + std::for_each(_children.cbegin()+i, _children.cend(), [](Node* node){ + node->visit(); + }); + } + else + { + this->draw(); + } + + // reset for next frame + _orderOfArrival = 0; + + if(_nodeGrid && _nodeGrid->isActive()) + { + // restore projection + Director *director = Director::getInstance(); + director->setProjection(beforeProjectionType); + } + + CustomCommand* gridEndCmd = CustomCommand::getCommandPool().generateCommand(); + gridEndCmd->init(0,_vertexZ); + gridEndCmd->func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this); + renderer->addCommand(gridEndCmd); + + renderer->popGroup(); + + kmGLPopMatrix(); +} + +void NodeGrid::setGrid(GridBase *grid) +{ + CC_SAFE_RELEASE(_nodeGrid); + CC_SAFE_RETAIN(grid); + _nodeGrid = grid; +} + +NS_CC_END diff --git a/cocos/2d/CCNodeGrid.h b/cocos/2d/CCNodeGrid.h new file mode 100644 index 0000000000..c5444ede2b --- /dev/null +++ b/cocos/2d/CCNodeGrid.h @@ -0,0 +1,47 @@ +#ifndef __MISCNODE_CCGRID_NODE_H__ +#define __MISCNODE_CCGRID_NODE_H__ + +#include "CCNode.h" +#include "kazmath/GL/matrix.h" + +NS_CC_BEGIN + +class GridBase; + +class NodeGrid : public Node +{ +public: + static NodeGrid* create(); + + GridBase* getGrid() { return _nodeGrid; } + /** + * @js NA + */ + const GridBase* getGrid() const { return _nodeGrid; } + + /** + * Changes a grid object that is used when applying effects + * + * @param grid A Grid object that is used when applying effects + */ + void setGrid(GridBase *grid); + + virtual bool init(); + virtual void visit(); + + void setTarget(Node *target); +protected: + NodeGrid(); + virtual ~NodeGrid(); + + void onGridBeginDraw(); + void onGridEndDraw(); + +protected: + kmMat4 _cachedMVmat; + Node* _gridTarget; + GridBase* _nodeGrid; +}; +NS_CC_END + +#endif \ No newline at end of file diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index c6fc006f76..d6e86dc2b4 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -135,21 +135,10 @@ void ParticleBatchNode::visit() kmGLPushMatrix(); - if ( _grid && _grid->isActive()) - { - _grid->beforeDraw(); - transformAncestors(); - } - transform(); draw(); - if ( _grid && _grid->isActive()) - { - _grid->afterDraw(this); - } - kmGLPopMatrix(); } diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index c935f2969b..d3d7b305a2 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -456,22 +456,11 @@ void RenderTexture::visit() } kmGLPushMatrix(); - - if (_grid && _grid->isActive()) - { - _grid->beforeDraw(); - transformAncestors(); - } transform(); _sprite->visit(); draw(); - if (_grid && _grid->isActive()) - { - _grid->afterDraw(this); - } - kmGLPopMatrix(); _orderOfArrival = 0; diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index d84f5983bd..2ed19e294d 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -146,21 +146,10 @@ void SpriteBatchNode::visit(void) kmGLPushMatrix(); - if (_grid && _grid->isActive()) - { - _grid->beforeDraw(); - transformAncestors(); - } - sortAllChildren(); transform(); draw(); - - if (_grid && _grid->isActive()) - { - _grid->afterDraw(this); - } kmGLPopMatrix(); setOrderOfArrival(0); diff --git a/cocos/2d/CCTransition.cpp b/cocos/2d/CCTransition.cpp index 97862fd815..13bd2a841e 100644 --- a/cocos/2d/CCTransition.cpp +++ b/cocos/2d/CCTransition.cpp @@ -35,6 +35,7 @@ THE SOFTWARE. #include "CCActionGrid.h" #include "CCLayer.h" #include "CCRenderTexture.h" +#include "CCNodeGrid.h" NS_CC_BEGIN @@ -1346,10 +1347,13 @@ void TransitionCrossFade::onExit() // TransitionTurnOffTiles::TransitionTurnOffTiles() { + _outSceneProxy = NodeGrid::create(); + _outSceneProxy->retain(); } TransitionTurnOffTiles::~TransitionTurnOffTiles() { + CC_SAFE_RELEASE(_outSceneProxy); } TransitionTurnOffTiles* TransitionTurnOffTiles::create(float t, Scene* scene) @@ -1373,6 +1377,9 @@ void TransitionTurnOffTiles::sceneOrder() void TransitionTurnOffTiles::onEnter() { TransitionScene::onEnter(); + _outSceneProxy->setTarget(_outScene); + _outSceneProxy->onEnter(); + Size s = Director::getInstance()->getWinSize(); float aspect = s.width / s.height; int x = (int)(12 * aspect); @@ -1380,7 +1387,7 @@ void TransitionTurnOffTiles::onEnter() TurnOffTiles* toff = TurnOffTiles::create(_duration, Size(x,y)); ActionInterval* action = easeActionWithAction(toff); - _outScene->runAction + _outSceneProxy->runAction ( Sequence::create ( @@ -1392,6 +1399,29 @@ void TransitionTurnOffTiles::onEnter() ); } +void TransitionTurnOffTiles::onExit() +{ + _outSceneProxy->setTarget(nullptr); + _outSceneProxy->onExit(); + TransitionScene::onExit(); +} + +void TransitionTurnOffTiles::draw() +{ + Scene::draw(); + + if( _isInSceneOnTop ) + { + _outSceneProxy->visit(); + _inScene->visit(); + } + else + { + _inScene->visit(); + _outSceneProxy->visit(); + } +} + ActionInterval* TransitionTurnOffTiles:: easeActionWithAction(ActionInterval* action) { @@ -1403,9 +1433,12 @@ ActionInterval* TransitionTurnOffTiles:: easeActionWithAction(ActionInterval* ac // TransitionSplitCols::TransitionSplitCols() { + _gridProxy = NodeGrid::create(); + _gridProxy->retain(); } TransitionSplitCols::~TransitionSplitCols() { + CC_SAFE_RELEASE(_gridProxy); } TransitionSplitCols* TransitionSplitCols::create(float t, Scene* scene) @@ -1423,18 +1456,20 @@ TransitionSplitCols* TransitionSplitCols::create(float t, Scene* scene) void TransitionSplitCols::onEnter() { TransitionScene::onEnter(); - _inScene->setVisible(false); + + _gridProxy->setTarget(_outScene); + _gridProxy->onEnter(); ActionInterval* split = action(); ActionInterval* seq = (ActionInterval*)Sequence::create ( split, - CallFunc::create(CC_CALLBACK_0(TransitionScene::hideOutShowIn,this)), + CallFunc::create(CC_CALLBACK_0(TransitionSplitCols::switchTargetToInscene,this)), split->reverse(), nullptr ); - this->runAction + _gridProxy->runAction ( Sequence::create ( @@ -1446,6 +1481,24 @@ void TransitionSplitCols::onEnter() ); } +void TransitionSplitCols::switchTargetToInscene() +{ + _gridProxy->setTarget(_inScene); +} + +void TransitionSplitCols::draw() +{ + Scene::draw(); + _gridProxy->visit(); +} + +void TransitionSplitCols::onExit() +{ + _gridProxy->setTarget(nullptr); + _gridProxy->onExit(); + TransitionScene::onExit(); +} + ActionInterval* TransitionSplitCols:: action() { return SplitCols::create(_duration/2.0f, 3); @@ -1491,9 +1544,12 @@ TransitionSplitRows* TransitionSplitRows::create(float t, Scene* scene) // TransitionFadeTR::TransitionFadeTR() { + _outSceneProxy = NodeGrid::create(); + _outSceneProxy->retain(); } TransitionFadeTR::~TransitionFadeTR() { + CC_SAFE_RELEASE(_outSceneProxy); } TransitionFadeTR* TransitionFadeTR::create(float t, Scene* scene) @@ -1517,6 +1573,9 @@ void TransitionFadeTR::onEnter() { TransitionScene::onEnter(); + _outSceneProxy->setTarget(_outScene); + _outSceneProxy->onEnter(); + Size s = Director::getInstance()->getWinSize(); float aspect = s.width / s.height; int x = (int)(12 * aspect); @@ -1524,7 +1583,7 @@ void TransitionFadeTR::onEnter() ActionInterval* action = actionWithSize(Size(x,y)); - _outScene->runAction + _outSceneProxy->runAction ( Sequence::create ( @@ -1536,6 +1595,28 @@ void TransitionFadeTR::onEnter() ); } +void TransitionFadeTR::onExit() +{ + _outSceneProxy->setTarget(nullptr); + _outSceneProxy->onExit(); + TransitionScene::onExit(); +} + +void TransitionFadeTR::draw() +{ + Scene::draw(); + + if( _isInSceneOnTop ) + { + _outSceneProxy->visit(); + _inScene->visit(); + } + else + { + _inScene->visit(); + _outSceneProxy->visit(); + } +} ActionInterval* TransitionFadeTR::actionWithSize(const Size& size) { diff --git a/cocos/2d/CCTransition.h b/cocos/2d/CCTransition.h index f2485d016e..136dafe568 100644 --- a/cocos/2d/CCTransition.h +++ b/cocos/2d/CCTransition.h @@ -43,6 +43,7 @@ NS_CC_BEGIN class ActionInterval; class Node; +class NodeGrid; /** @brief TransitionEaseScene can ease the actions of the scene protocol. @since v0.8.2 @@ -643,13 +644,16 @@ public : * @lua NA */ virtual void onEnter() override; + virtual void onExit() override; virtual ActionInterval * easeActionWithAction(ActionInterval * action) override; + virtual void draw() override; protected: TransitionTurnOffTiles(); virtual ~TransitionTurnOffTiles(); virtual void sceneOrder() override; + NodeGrid* _outSceneProxy; private: CC_DISALLOW_COPY_AND_ASSIGN(TransitionTurnOffTiles); @@ -674,11 +678,13 @@ public: */ virtual void onEnter() override; virtual ActionInterval * easeActionWithAction(ActionInterval * action) override; - + virtual void onExit() override; + virtual void draw() override; protected: TransitionSplitCols(); virtual ~TransitionSplitCols(); - + void switchTargetToInscene(); + NodeGrid* _gridProxy; private: CC_DISALLOW_COPY_AND_ASSIGN(TransitionSplitCols); }; @@ -723,13 +729,16 @@ public: */ virtual void onEnter() override; virtual ActionInterval* easeActionWithAction(ActionInterval * action) override; - + virtual void onExit() override; + virtual void draw() override; protected: TransitionFadeTR(); virtual ~TransitionFadeTR(); virtual void sceneOrder(); + NodeGrid* _outSceneProxy; + private: CC_DISALLOW_COPY_AND_ASSIGN(TransitionFadeTR); }; diff --git a/cocos/2d/CCTransitionPageTurn.cpp b/cocos/2d/CCTransitionPageTurn.cpp index 13977507db..f7b0188143 100644 --- a/cocos/2d/CCTransitionPageTurn.cpp +++ b/cocos/2d/CCTransitionPageTurn.cpp @@ -29,6 +29,7 @@ THE SOFTWARE. #include "CCActionInstant.h" #include "CCActionGrid.h" #include "CCActionPageTurn3D.h" +#include "CCNodeGrid.h" NS_CC_BEGIN @@ -37,10 +38,17 @@ float TransitionPageTurn::POLYGON_OFFSET_UNITS = -20.f; TransitionPageTurn::TransitionPageTurn() { + _inSceneProxy = NodeGrid::create(); + _outSceneProxy = NodeGrid::create(); + + _inSceneProxy->retain(); + _outSceneProxy->retain(); } TransitionPageTurn::~TransitionPageTurn() { + CC_SAFE_RELEASE(_inSceneProxy); + CC_SAFE_RELEASE(_outSceneProxy); } /** creates a base transition with duration and incoming scene */ @@ -75,17 +83,17 @@ void TransitionPageTurn::draw() Scene::draw(); if( _isInSceneOnTop ) { - _outScene->visit(); + _outSceneProxy->visit(); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(POLYGON_OFFSET_FACTOR, POLYGON_OFFSET_UNITS); - _inScene->visit(); + _inSceneProxy->visit(); glDisable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0, 0); } else { - _inScene->visit(); + _inSceneProxy->visit(); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(POLYGON_OFFSET_FACTOR, POLYGON_OFFSET_UNITS); - _outScene->visit(); + _outSceneProxy->visit(); glDisable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0, 0); } @@ -94,6 +102,13 @@ void TransitionPageTurn::draw() void TransitionPageTurn::onEnter() { TransitionScene::onEnter(); + + _inSceneProxy->setTarget(_inScene); + _outSceneProxy->setTarget(_outScene); + + _inSceneProxy->onEnter(); + _outSceneProxy->onEnter(); + Size s = Director::getInstance()->getWinSize(); int x,y; if (s.width > s.height) @@ -111,7 +126,7 @@ void TransitionPageTurn::onEnter() if (! _back ) { - _outScene->runAction + _outSceneProxy->runAction ( Sequence::create ( @@ -125,8 +140,8 @@ void TransitionPageTurn::onEnter() else { // to prevent initial flicker - _inScene->setVisible(false); - _inScene->runAction + _inSceneProxy->setVisible(false); + _inSceneProxy->runAction ( Sequence::create ( @@ -139,7 +154,15 @@ void TransitionPageTurn::onEnter() ); } } - +void TransitionPageTurn::onExit() +{ + _outSceneProxy->setTarget(nullptr); + _outSceneProxy->setTarget(nullptr); + _outSceneProxy->onExit(); + _inSceneProxy->onExit(); + + TransitionScene::onExit(); +} ActionInterval* TransitionPageTurn:: actionWithSize(const Size& vector) { diff --git a/cocos/2d/CCTransitionPageTurn.h b/cocos/2d/CCTransitionPageTurn.h index 3f0eca219d..7230f2bd51 100644 --- a/cocos/2d/CCTransitionPageTurn.h +++ b/cocos/2d/CCTransitionPageTurn.h @@ -30,6 +30,8 @@ THE SOFTWARE. NS_CC_BEGIN +class NodeGrid; + /** * @addtogroup transition * @{ @@ -83,11 +85,14 @@ public: // Overrides // virtual void onEnter() override; + virtual void onExit() override; protected: virtual void sceneOrder() override; protected: + NodeGrid* _inSceneProxy; + NodeGrid* _outSceneProxy; bool _back; static float POLYGON_OFFSET_FACTOR; static float POLYGON_OFFSET_UNITS; diff --git a/cocos/2d/CMakeLists.txt b/cocos/2d/CMakeLists.txt index e19a5e2f2b..dfa1ce2709 100644 --- a/cocos/2d/CMakeLists.txt +++ b/cocos/2d/CMakeLists.txt @@ -63,6 +63,7 @@ set(COCOS2D_SRC CCDrawNode.cpp CCGrabber.cpp CCGrid.cpp + CCNodeGrid.cpp CCFont.cpp CCFontAtlas.cpp CCFontAtlasCache.cpp diff --git a/cocos/2d/cocos2d.vcxproj b/cocos/2d/cocos2d.vcxproj index 827704b4ad..b82197cfe3 100644 --- a/cocos/2d/cocos2d.vcxproj +++ b/cocos/2d/cocos2d.vcxproj @@ -257,6 +257,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + @@ -442,6 +443,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou + diff --git a/cocos/2d/cocos2d.vcxproj.filters b/cocos/2d/cocos2d.vcxproj.filters index e7e447cb45..bdad847173 100644 --- a/cocos/2d/cocos2d.vcxproj.filters +++ b/cocos/2d/cocos2d.vcxproj.filters @@ -569,6 +569,9 @@ base + + misc_nodes + label_nodes @@ -1188,6 +1191,9 @@ base + + misc_nodes + label_nodes diff --git a/cocos/2d/renderer/CCGroupCommand.cpp b/cocos/2d/renderer/CCGroupCommand.cpp index f9dac2f01e..d057b00218 100644 --- a/cocos/2d/renderer/CCGroupCommand.cpp +++ b/cocos/2d/renderer/CCGroupCommand.cpp @@ -68,6 +68,7 @@ int GroupCommandManager::getGroupID() { if(!it->second) { + _groupMapping[it->first] = true; return it->first; } } diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index 3ecaf17d3d..545e1dff38 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -444,11 +444,6 @@ void Armature::visit() } kmGLPushMatrix(); - if (_grid && _grid->isActive()) - { - _grid->beforeDraw(); - } - transform(); sortAllChildren(); draw(); @@ -456,11 +451,6 @@ void Armature::visit() // reset for next frame _orderOfArrival = 0; - if (_grid && _grid->isActive()) - { - _grid->afterDraw(this); - } - kmGLPopMatrix(); } diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index 8e605bfd1c..f441ade370 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -101,11 +101,6 @@ void BatchNode::visit() } kmGLPushMatrix(); - if (_grid && _grid->isActive()) - { - _grid->beforeDraw(); - } - transform(); sortAllChildren(); draw(); @@ -113,11 +108,6 @@ void BatchNode::visit() // reset for next frame _orderOfArrival = 0; - if (_grid && _grid->isActive()) - { - _grid->afterDraw(this); - } - kmGLPopMatrix(); } diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index 905d27d360..81cc046366 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -6ea6ffc183c8a15eae0641c73c9886b90172266f \ No newline at end of file +cb193c00a0514b8292266fba55b5f97cbebb73bd \ No newline at end of file diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index 9e1b7ffa1f..4a8ab31c81 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -549,12 +549,6 @@ void ScrollView::visit() } kmGLPushMatrix(); - - if (_grid && _grid->isActive()) - { - _grid->beforeDraw(); - this->transformAncestors(); - } this->transform(); this->beforeDraw(); @@ -594,10 +588,6 @@ void ScrollView::visit() } this->afterDraw(); - if ( _grid && _grid->isActive()) - { - _grid->afterDraw(this); - } kmGLPopMatrix(); } diff --git a/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp b/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp index b53264bb1f..af32750dcd 100644 --- a/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp +++ b/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp @@ -1,4 +1,5 @@ #include "EffectsAdvancedTest.h" +#include "CCNodeGrid.h" enum { @@ -20,7 +21,7 @@ void Effect1::onEnter() { EffectAdvanceTextLayer::onEnter(); - auto target = getChildByTag(kTagBackground); + //auto target = getChildByTag(kTagBackground); // To reuse a grid the grid size and the grid type must be the same. // in this case: @@ -37,8 +38,8 @@ void Effect1::onEnter() auto orbit = OrbitCamera::create(5, 1, 2, 0, 180, 0, -90); auto orbit_back = orbit->reverse(); - target->runAction( RepeatForever::create( Sequence::create( orbit, orbit_back, NULL) ) ); - target->runAction( Sequence::create(lens, delay, reuse, waves, NULL) ); + //_bgNode->runAction( RepeatForever::create( Sequence::create( orbit, orbit_back, NULL) ) ); + _bgNode->runAction( Sequence::create(lens, delay, reuse, waves, NULL) ); } std::string Effect1::title() const @@ -55,7 +56,7 @@ void Effect2::onEnter() { EffectAdvanceTextLayer::onEnter(); - auto target = getChildByTag(kTagBackground); + //auto target = getChildByTag(kTagBackground); // To reuse a grid the grid size and the grid type must be the same. // in this case: @@ -78,8 +79,8 @@ void Effect2::onEnter() // id orbit = [OrbitCamera::create:5 radius:1 deltaRadius:2 angleZ:0 deltaAngleZ:180 angleX:0 deltaAngleX:-90]; // id orbit_back = [orbit reverse]; // -// [target runAction: [RepeatForever::create: [Sequence actions: orbit, orbit_back, nil]]]; - target->runAction(Sequence::create( shaky, delay, reuse, shuffle, delay->clone(), turnoff, turnon, NULL) ); +// [target runAction: [RepeatForever::create: [Sequence actions: orbit, orbit_back, nil]]]; + _bgNode->runAction(Sequence::create( shaky, delay, reuse, shuffle, delay->clone(), turnoff, turnon, NULL) ); } std::string Effect2::title() const @@ -96,20 +97,18 @@ std::string Effect2::title() const void Effect3::onEnter() { EffectAdvanceTextLayer::onEnter(); - - auto bg = getChildByTag(kTagBackground); - auto target1 = bg->getChildByTag(kTagSprite1); - auto target2 = bg->getChildByTag(kTagSprite2); - + //auto bg = getChildByTag(kTagBackground); + //auto target1 = bg->getChildByTag(kTagSprite1); + //auto target2 = bg->getChildByTag(kTagSprite2); auto waves = Waves::create(5, Size(15,10), 5, 20, true, false); auto shaky = Shaky3D::create(5, Size(15,10), 4, false); - target1->runAction( RepeatForever::create( waves ) ); - target2->runAction( RepeatForever::create( shaky ) ); + _target1->runAction( RepeatForever::create( waves ) ); + _target2->runAction( RepeatForever::create( shaky ) ); // moving background. Testing issue #244 auto move = MoveBy::create(3, Point(200,0) ); - bg->runAction(RepeatForever::create( Sequence::create(move, move->reverse(), NULL) )); + _bgNode->runAction(RepeatForever::create( Sequence::create(move, move->reverse(), NULL) )); } std::string Effect3::title() const @@ -156,7 +155,8 @@ private: void Effect4::onEnter() { EffectAdvanceTextLayer::onEnter(); - + //Node* gridNode = NodeGrid::create(); + auto lens = Lens3D::create(10, Size(32,24), Point(100,180), 150); auto move = JumpBy::create(5, Point(380,0), 100, 4); auto move_back = move->reverse(); @@ -171,9 +171,11 @@ void Effect4::onEnter() auto pTarget = Lens3DTarget::create(lens); // Please make sure the target been added to its parent. this->addChild(pTarget); + //gridNode->addChild(pTarget); director->getActionManager()->addAction(seq, pTarget, false); - this->runAction( lens ); + + _bgNode->runAction( lens ); } std::string Effect4::title() const @@ -202,8 +204,8 @@ void Effect5::onEnter() // [[effect copy] autorelease], NULL); - auto bg = getChildByTag(kTagBackground); - bg->runAction(stopEffect); + //auto bg = getChildByTag(kTagBackground); + _bgNode->runAction(stopEffect); } std::string Effect5::title() const @@ -230,8 +232,8 @@ void Issue631::onEnter() auto effect = Sequence::create( DelayTime::create(2.0f), Shaky3D::create(5.0f, Size(5, 5), 16, false), NULL); // cleanup - auto bg = getChildByTag(kTagBackground); - removeChild(bg, true); + //auto bg = getChildByTag(kTagBackground); + removeChild(_bgNode, true); // background auto layer = LayerColor::create( Color4B(255,0,0,255) ); @@ -241,15 +243,17 @@ void Issue631::onEnter() layer->addChild(sprite, 10); // foreground + auto layer2BaseGrid = NodeGrid::create(); auto layer2 = LayerColor::create(Color4B( 0, 255,0,255 ) ); auto fog = Sprite::create("Images/Fog.png"); BlendFunc bf = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}; fog->setBlendFunc(bf); layer2->addChild(fog, 1); - addChild(layer2, 1); + addChild(layer2BaseGrid, 1); + layer2BaseGrid->addChild(layer2); - layer2->runAction( RepeatForever::create(effect) ); + layer2BaseGrid->runAction( RepeatForever::create(effect) ); } std::string Issue631::title() const @@ -335,23 +339,37 @@ void EffectAdvanceTextLayer::onEnter(void) { BaseTest::onEnter(); + _bgNode = NodeGrid::create(); + _bgNode->setAnchorPoint(Point(0.5,0.5)); + addChild(_bgNode); + //_bgNode->setPosition( VisibleRect::center() ); auto bg = Sprite::create("Images/background3.png"); - addChild(bg, 0, kTagBackground); bg->setPosition( VisibleRect::center() ); - + //addChild(bg, 0, kTagBackground); + //bg->setPosition( VisibleRect::center() ); + _bgNode->addChild(bg); + + _target1 = NodeGrid::create(); + _target1->setAnchorPoint(Point(0.5,0.5)); auto grossini = Sprite::create("Images/grossinis_sister2.png"); - bg->addChild(grossini, 1, kTagSprite1); - grossini->setPosition( Point(VisibleRect::left().x+VisibleRect::getVisibleRect().size.width/3.0f, VisibleRect::bottom().y+ 200) ); + _target1->addChild(grossini); + _bgNode->addChild(_target1); + _target1->setPosition( Point(VisibleRect::left().x+VisibleRect::getVisibleRect().size.width/3.0f, VisibleRect::bottom().y+ 200) ); auto sc = ScaleBy::create(2, 5); auto sc_back = sc->reverse(); - grossini->runAction( RepeatForever::create(Sequence::create(sc, sc_back, NULL) ) ); + _target1->runAction( RepeatForever::create(Sequence::create(sc, sc_back, NULL) ) ); + + _target2 = NodeGrid::create(); + _target2->setAnchorPoint(Point(0.5,0.5)); auto tamara = Sprite::create("Images/grossinis_sister1.png"); - bg->addChild(tamara, 1, kTagSprite2); - tamara->setPosition( Point(VisibleRect::left().x+2*VisibleRect::getVisibleRect().size.width/3.0f,VisibleRect::bottom().y+200) ); + _target2->addChild(tamara); + _bgNode->addChild(_target2); + _target2->setPosition( Point(VisibleRect::left().x+2*VisibleRect::getVisibleRect().size.width/3.0f,VisibleRect::bottom().y+200) ); auto sc2 = ScaleBy::create(2, 5); auto sc2_back = sc2->reverse(); - tamara->runAction( RepeatForever::create(Sequence::create(sc2, sc2_back, NULL) ) ); + _target2->runAction( RepeatForever::create(Sequence::create(sc2, sc2_back, NULL) ) ); + } EffectAdvanceTextLayer::~EffectAdvanceTextLayer(void) diff --git a/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h b/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h index 8f02c5a527..9662243e17 100644 --- a/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h +++ b/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h @@ -12,6 +12,10 @@ protected: std::string _title; + Node* _bgNode; + Node* _target1; + Node* _target2; + public: virtual void onEnter(); ~EffectAdvanceTextLayer(void); diff --git a/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.cpp b/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.cpp index bc08aa37b4..79b6efd4b7 100644 --- a/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.cpp @@ -1,6 +1,6 @@ #include "EffectsTest.h" #include "../testResource.h" - +#include "CCNodeGrid.h" enum { kTagTextLayer = 1, @@ -342,25 +342,25 @@ TextLayer::TextLayer(void) LayerColor *background = LayerColor::create( Color4B(32,128,32,255) ); this->addChild(background,-20); - auto node = Node::create(); + _gridNodeTarget = NodeGrid::create(); auto effect = getAction(); - node->runAction(effect); - addChild(node, 0, kTagBackground); + _gridNodeTarget->runAction(effect); + addChild(_gridNodeTarget, 0, kTagBackground); auto bg = Sprite::create(s_back3); - node->addChild(bg, 0); + _gridNodeTarget->addChild(bg, 0); // bg->setAnchorPoint( Point::ZERO ); bg->setPosition(VisibleRect::center()); auto grossini = Sprite::create(s_pathSister2); - node->addChild(grossini, 1); + _gridNodeTarget->addChild(grossini, 1); grossini->setPosition( Point(VisibleRect::left().x+VisibleRect::getVisibleRect().size.width/3,VisibleRect::center().y) ); auto sc = ScaleBy::create(2, 5); auto sc_back = sc->reverse(); grossini->runAction( RepeatForever::create(Sequence::create(sc, sc_back, NULL) ) ); auto tamara = Sprite::create(s_pathSister1); - node->addChild(tamara, 1); + _gridNodeTarget->addChild(tamara, 1); tamara->setPosition( Point(VisibleRect::left().x+2*VisibleRect::getVisibleRect().size.width/3,VisibleRect::center().y) ); auto sc2 = ScaleBy::create(2, 5); auto sc2_back = sc2->reverse(); @@ -377,9 +377,9 @@ TextLayer::TextLayer(void) void TextLayer::checkAnim(float dt) { - auto s2 = getChildByTag(kTagBackground); - if ( s2->getNumberOfRunningActions() == 0 && s2->getGrid() != NULL) - s2->setGrid(NULL);; + //auto s2 = getChildByTag(kTagBackground); + if ( _gridNodeTarget->getNumberOfRunningActions() == 0 && _gridNodeTarget->getGrid() != NULL) + _gridNodeTarget->setGrid(NULL);; } diff --git a/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.h b/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.h index 2f65c73711..6772578b45 100644 --- a/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.h +++ b/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.h @@ -14,7 +14,7 @@ class TextLayer : public BaseTest { protected: //UxString _title; - + NodeGrid* _gridNodeTarget; public: TextLayer(void); ~TextLayer(void); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 37f6f0e7ba..3428885e99 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -1,6 +1,7 @@ #include "ArmatureScene.h" #include "../../testResource.h" #include "cocostudio/CocoStudio.h" +#include "CCNodeGrid.h" using namespace cocos2d; @@ -574,6 +575,7 @@ void TestAnimationEvent::callback2() void TestFrameEvent::onEnter() { ArmatureTestLayer::onEnter(); + _gridNode = NodeGrid::create(); Armature *armature = Armature::create("HeroAnimation"); armature->getAnimation()->play("attack"); armature->getAnimation()->setSpeedScale(0.5); @@ -584,7 +586,9 @@ void TestFrameEvent::onEnter() * To disconnect this event, just setFrameEventCallFunc(nullptr); */ armature->getAnimation()->setFrameEventCallFunc(CC_CALLBACK_0(TestFrameEvent::onFrameEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); - addChild(armature); + + _gridNode->addChild(armature); + addChild(_gridNode); schedule( schedule_selector(TestFrameEvent::checkAction) ); } @@ -596,20 +600,19 @@ void TestFrameEvent::onFrameEvent(Bone *bone, const char *evt, int originFrameIn { CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt, currentFrameIndex); + if (!_gridNode->getActionByTag(FRAME_EVENT_ACTION_TAG) || _gridNode->getActionByTag(FRAME_EVENT_ACTION_TAG)->isDone()) + { + _gridNode->stopAllActions(); -// if (!this->getActionByTag(FRAME_EVENT_ACTION_TAG) || this->getActionByTag(FRAME_EVENT_ACTION_TAG)->isDone()) -// { -// this->stopAllActions(); -// -// ActionInterval *action = ShatteredTiles3D::create(0.2f, Size(16,12), 5, false); -// action->setTag(FRAME_EVENT_ACTION_TAG); -// this->runAction(action); -// } + ActionInterval *action = ShatteredTiles3D::create(0.2f, Size(16,12), 5, false); + action->setTag(FRAME_EVENT_ACTION_TAG); + _gridNode->runAction(action); + } } void TestFrameEvent::checkAction(float dt) { - if ( this->getNumberOfRunningActions() == 0 && this->getGrid() != nullptr) - this->setGrid(nullptr); + if ( _gridNode->getNumberOfRunningActions() == 0 && _gridNode->getGrid() != nullptr) + _gridNode->setGrid(nullptr); } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index 933a1edf59..b17a5a0163 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -168,6 +168,8 @@ public: virtual std::string title() const override; void onFrameEvent(cocostudio::Bone *bone, const char *evt, int originFrameIndex, int currentFrameIndex); void checkAction(float dt); +protected: + NodeGrid* _gridNode; };