2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-04-19 14:35:52 +08:00
|
|
|
Copyright (c) 2009 On-Core
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
#include "CCActionGrid.h"
|
|
|
|
#include "CCDirector.h"
|
|
|
|
#include "effects/CCGrid.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "cocoa/CCZone.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of GridAction
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool GridAction::initWithDuration(float duration, const Size& gridSize)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_gridSize = gridSize;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void GridAction::startWithTarget(Node *pTarget)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
GridBase *newgrid = this->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Node *t = _target;
|
|
|
|
GridBase *targetGrid = t->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
if (targetGrid && targetGrid->getReuseGrid() > 0)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (targetGrid->isActive() && targetGrid->getGridSize().width == _gridSize.width
|
2013-06-20 14:13:12 +08:00
|
|
|
&& targetGrid->getGridSize().height == _gridSize.height /*&& dynamic_cast<GridBase*>(targetGrid) != NULL*/)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
targetGrid->reuse();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCAssert(0, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (targetGrid && targetGrid->isActive())
|
|
|
|
{
|
|
|
|
targetGrid->setActive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
t->setGrid(newgrid);
|
|
|
|
t->getGrid()->setActive(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
GridAction* GridAction::reverse() const
|
2013-06-16 09:54:34 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return (GridAction*)ReverseTime::create( this->clone() );
|
2013-06-16 09:54:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
GridBase* GridAction::getGrid(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// Abstract class needs implementation
|
|
|
|
CCAssert(0, "");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of Grid3DAction
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
GridBase* Grid3DAction::getGrid(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return Grid3D::create(_gridSize);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ccVertex3F Grid3DAction::vertex(const Point& position)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Grid3D *g = (Grid3D*)_target->getGrid();
|
2012-12-26 18:59:31 +08:00
|
|
|
return g->vertex(position);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ccVertex3F Grid3DAction::originalVertex(const Point& position)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Grid3D *g = (Grid3D*)_target->getGrid();
|
2012-12-26 18:59:31 +08:00
|
|
|
return g->originalVertex(position);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Grid3DAction::setVertex(const Point& position, const ccVertex3F& vertex)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Grid3D *g = (Grid3D*)_target->getGrid();
|
2012-12-26 18:59:31 +08:00
|
|
|
g->setVertex(position, vertex);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of TiledGrid3DAction
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
GridBase* TiledGrid3DAction::getGrid(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return TiledGrid3D::create(_gridSize);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ccQuad3 TiledGrid3DAction::tile(const Point& pos)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TiledGrid3D *g = (TiledGrid3D*)_target->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
return g->tile(pos);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ccQuad3 TiledGrid3DAction::originalTile(const Point& pos)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TiledGrid3D *g = (TiledGrid3D*)_target->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
return g->originalTile(pos);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void TiledGrid3DAction::setTile(const Point& pos, const ccQuad3& coords)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TiledGrid3D *g = (TiledGrid3D*)_target->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
return g->setTile(pos, coords);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation AccelDeccelAmplitude
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelDeccelAmplitude* AccelDeccelAmplitude::create(Action *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelDeccelAmplitude *pRet = new AccelDeccelAmplitude();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet)
|
|
|
|
{
|
|
|
|
if (pRet->initWithAction(pAction, duration))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool AccelDeccelAmplitude::initWithAction(Action *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_rate = 1.0f;
|
2013-06-20 14:13:12 +08:00
|
|
|
_other = (ActionInterval*)(pAction);
|
2012-04-19 14:35:52 +08:00
|
|
|
pAction->retain();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelDeccelAmplitude* AccelDeccelAmplitude::clone() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new AccelDeccelAmplitude();
|
2013-06-19 00:59:34 +08:00
|
|
|
a->initWithAction(_other->clone(), _rate);
|
2013-06-16 03:38:32 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelDeccelAmplitude::~AccelDeccelAmplitude(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void AccelDeccelAmplitude::startWithTarget(Node *pTarget)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
_other->startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void AccelDeccelAmplitude::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
float f = time * 2;
|
|
|
|
|
|
|
|
if (f > 1)
|
|
|
|
{
|
|
|
|
f -= 1;
|
|
|
|
f = 1 - f;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
((AccelDeccelAmplitude*)(_other))->setAmplitudeRate(powf(f, _rate));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelDeccelAmplitude* AccelDeccelAmplitude::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return AccelDeccelAmplitude::create(_other->reverse(), _duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of AccelAmplitude
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelAmplitude* AccelAmplitude::create(Action *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelAmplitude *pRet = new AccelAmplitude();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet)
|
|
|
|
{
|
|
|
|
if (pRet->initWithAction(pAction, duration))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool AccelAmplitude::initWithAction(Action *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_rate = 1.0f;
|
2013-06-20 14:13:12 +08:00
|
|
|
_other = (ActionInterval*)(pAction);
|
2012-04-19 14:35:52 +08:00
|
|
|
pAction->retain();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelAmplitude* AccelAmplitude::clone() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new AccelAmplitude();
|
2013-06-19 00:59:34 +08:00
|
|
|
a->initWithAction(_other->clone(), _duration);
|
2013-06-16 03:38:32 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelAmplitude::~AccelAmplitude(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_DELETE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void AccelAmplitude::startWithTarget(Node *pTarget)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
_other->startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void AccelAmplitude::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
((AccelAmplitude*)(_other))->setAmplitudeRate(powf(time, _rate));
|
2013-06-15 14:03:30 +08:00
|
|
|
_other->update(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelAmplitude* AccelAmplitude::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return AccelAmplitude::create(_other->reverse(), _duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeccelAmplitude
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
DeccelAmplitude* DeccelAmplitude::create(Action *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
DeccelAmplitude *pRet = new DeccelAmplitude();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet)
|
|
|
|
{
|
|
|
|
if (pRet->initWithAction(pAction, duration))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool DeccelAmplitude::initWithAction(Action *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_rate = 1.0f;
|
2013-06-20 14:13:12 +08:00
|
|
|
_other = (ActionInterval*)(pAction);
|
2012-04-19 14:35:52 +08:00
|
|
|
pAction->retain();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
DeccelAmplitude::~DeccelAmplitude(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void DeccelAmplitude::startWithTarget(Node *pTarget)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
_other->startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void DeccelAmplitude::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
((DeccelAmplitude*)(_other))->setAmplitudeRate(powf((1 - time), _rate));
|
2013-06-15 14:03:30 +08:00
|
|
|
_other->update(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
DeccelAmplitude* DeccelAmplitude::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new DeccelAmplitude();
|
2013-06-19 00:59:34 +08:00
|
|
|
a->initWithAction(_other->clone(), _duration);
|
2013-06-16 10:44:39 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
DeccelAmplitude* DeccelAmplitude::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return DeccelAmplitude::create(_other->reverse(), _duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of StopGrid
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void StopGrid::startWithTarget(Node *pTarget)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant::startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
GridBase *pGrid = _target->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pGrid && pGrid->isActive())
|
|
|
|
{
|
|
|
|
pGrid->setActive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
StopGrid* StopGrid::create(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
StopGrid* pAction = new StopGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
pAction->autorelease();
|
|
|
|
|
|
|
|
return pAction;
|
|
|
|
}
|
2013-06-16 10:44:39 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
StopGrid* StopGrid::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return StopGrid::create();
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
StopGrid* StopGrid::reverse() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
|
|
|
// no reverse, just clone it
|
|
|
|
return this->clone();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of ReuseGrid
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ReuseGrid* ReuseGrid::create(int times)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ReuseGrid *pAction = new ReuseGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pAction)
|
|
|
|
{
|
|
|
|
if (pAction->initWithTimes(times))
|
|
|
|
{
|
|
|
|
pAction->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pAction;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool ReuseGrid::initWithTimes(int times)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_times = times;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ReuseGrid::startWithTarget(Node *pTarget)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant::startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_target->getGrid() && _target->getGrid()->isActive())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->getGrid()->setReuseGrid(_target->getGrid()->getReuseGrid() + _times);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ReuseGrid* ReuseGrid::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return ReuseGrid::create(_times);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ReuseGrid* ReuseGrid::reverse() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
|
|
|
// no reverse, just clone it
|
|
|
|
return this->clone();
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|