2010-11-13 11:34:49 +08:00
|
|
|
/****************************************************************************
|
2012-06-14 17:18:05 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-09-05 10:12:14 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2011-03-19 10:34:26 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2010-11-13 11:34:49 +08:00
|
|
|
|
2010-12-22 15:15:04 +08:00
|
|
|
#include "CCActionInstant.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "base_nodes/CCNode.h"
|
|
|
|
#include "sprite_nodes/CCSprite.h"
|
2012-08-21 18:42:35 +08:00
|
|
|
#include "script_support/CCScriptSupport.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "cocoa/CCZone.h"
|
2011-01-15 18:05:35 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// InstantAction
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
bool ActionInstant::isDone() {
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ActionInstant::step(float dt) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(dt);
|
|
|
|
update(1);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ActionInstant::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
|
|
|
// nothing
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Show
|
|
|
|
//
|
2012-06-14 17:18:05 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Show* Show::create()
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Show* pRet = new Show();
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet) {
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Show::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setVisible(true);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant* Show::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return Hide::create();
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Show * Show::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new Show();
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Object* Show::copyWithZone(Zone *pZone) {
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Zone *pNewZone = NULL;
|
|
|
|
Show *pRet = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
if (pZone && pZone->_copyObject) {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = (Show*) (pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
} else {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = new Show();
|
|
|
|
pZone = pNewZone = new Zone(pRet);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant::copyWithZone(pZone);
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Hide
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
Hide * Hide::create()
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Hide *pRet = new Hide();
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet) {
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Hide::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setVisible(false);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant *Hide::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return Show::create();
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Hide * Hide::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new Hide();
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Object* Hide::copyWithZone(Zone *pZone) {
|
|
|
|
Zone *pNewZone = NULL;
|
|
|
|
Hide *pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (pZone && pZone->_copyObject) {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = (Hide*) (pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
} else {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = new Hide();
|
|
|
|
pZone = pNewZone = new Zone(pRet);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant::copyWithZone(pZone);
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ToggleVisibility
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
ToggleVisibility * ToggleVisibility::create()
|
2012-05-30 16:34:42 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ToggleVisibility *pRet = new ToggleVisibility();
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-05-30 16:34:42 +08:00
|
|
|
if (pRet)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
pRet->autorelease();
|
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ToggleVisibility::update(float time)
|
2012-05-30 16:34:42 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setVisible(!_target->isVisible());
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ToggleVisibility * ToggleVisibility::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return ToggleVisibility::create();
|
2013-06-16 03:38:32 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ToggleVisibility * ToggleVisibility::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new ToggleVisibility();
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Object* ToggleVisibility::copyWithZone(Zone *pZone)
|
2012-05-30 16:34:42 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Zone *pNewZone = NULL;
|
|
|
|
ToggleVisibility *pRet = NULL;
|
2012-05-30 16:34:42 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (pZone && pZone->_copyObject) {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = (ToggleVisibility*) (pZone->_copyObject);
|
2012-05-30 16:34:42 +08:00
|
|
|
} else {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = new ToggleVisibility();
|
|
|
|
pZone = pNewZone = new Zone(pRet);
|
2012-05-30 16:34:42 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant::copyWithZone(pZone);
|
2012-05-30 16:34:42 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-03-25 11:10:51 +08:00
|
|
|
//
|
|
|
|
// Remove Self
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
RemoveSelf * RemoveSelf::create(bool isNeedCleanUp /*= true*/)
|
2013-03-25 11:10:51 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
RemoveSelf *pRet = new RemoveSelf();
|
2013-03-25 11:10:51 +08:00
|
|
|
|
2013-03-25 18:18:38 +08:00
|
|
|
if (pRet && pRet->init(isNeedCleanUp)) {
|
2013-03-25 11:10:51 +08:00
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool RemoveSelf::init(bool isNeedCleanUp) {
|
2013-06-15 14:03:30 +08:00
|
|
|
_isNeedCleanUp = isNeedCleanUp;
|
2013-03-25 18:18:38 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void RemoveSelf::update(float time) {
|
2013-03-25 11:10:51 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->removeFromParentAndCleanup(_isNeedCleanUp);
|
2013-03-25 11:10:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
RemoveSelf *RemoveSelf::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return RemoveSelf::create(_isNeedCleanUp);
|
2013-03-25 11:10:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
RemoveSelf * RemoveSelf::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new RemoveSelf();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->init(_isNeedCleanUp);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Object* RemoveSelf::copyWithZone(Zone *pZone) {
|
|
|
|
Zone *pNewZone = NULL;
|
|
|
|
RemoveSelf *pRet = NULL;
|
2013-03-25 11:10:51 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (pZone && pZone->_copyObject) {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = (RemoveSelf*) (pZone->_copyObject);
|
2013-03-25 11:10:51 +08:00
|
|
|
} else {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = new RemoveSelf();
|
|
|
|
pZone = pNewZone = new Zone(pRet);
|
2013-03-25 11:10:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant::copyWithZone(pZone);
|
2013-06-15 14:03:30 +08:00
|
|
|
pRet->init(_isNeedCleanUp);
|
2013-03-25 11:10:51 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// FlipX
|
|
|
|
//
|
2012-06-14 17:18:05 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipX *FlipX::create(bool x)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipX *pRet = new FlipX();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet && pRet->initWithFlipX(x)) {
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool FlipX::initWithFlipX(bool x) {
|
2013-06-15 14:03:30 +08:00
|
|
|
_flipX = x;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void FlipX::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
2013-06-20 14:13:12 +08:00
|
|
|
((Sprite*) (_target))->setFlipX(_flipX);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipX* FlipX::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return FlipX::create(!_flipX);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipX * FlipX::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new FlipX();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->initWithFlipX(_flipX);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Object * FlipX::copyWithZone(Zone *pZone) {
|
|
|
|
Zone *pNewZone = NULL;
|
|
|
|
FlipX *pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (pZone && pZone->_copyObject) {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = (FlipX*) (pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
} else {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = new FlipX();
|
|
|
|
pZone = pNewZone = new Zone(pRet);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-08-25 19:04:29 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant::copyWithZone(pZone);
|
2013-06-15 14:03:30 +08:00
|
|
|
pRet->initWithFlipX(_flipX);
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// FlipY
|
|
|
|
//
|
2012-06-14 17:18:05 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipY * FlipY::create(bool y)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipY *pRet = new FlipY();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet && pRet->initWithFlipY(y)) {
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool FlipY::initWithFlipY(bool y) {
|
2013-06-15 14:03:30 +08:00
|
|
|
_flipY = y;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void FlipY::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
2013-06-20 14:13:12 +08:00
|
|
|
((Sprite*) (_target))->setFlipY(_flipY);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipY* FlipY::reverse() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return FlipY::create(!_flipY);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FlipY * FlipY::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new FlipY();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->initWithFlipY(_flipY);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Object* FlipY::copyWithZone(Zone *pZone) {
|
|
|
|
Zone *pNewZone = NULL;
|
|
|
|
FlipY *pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (pZone && pZone->_copyObject) {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = (FlipY*) (pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
} else {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = new FlipY();
|
|
|
|
pZone = pNewZone = new Zone(pRet);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant::copyWithZone(pZone);
|
2013-06-15 14:03:30 +08:00
|
|
|
pRet->initWithFlipY(_flipY);
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Place
|
|
|
|
//
|
2012-06-14 17:18:05 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Place* Place::create(const Point& pos)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Place *pRet = new Place();
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet && pRet->initWithPosition(pos)) {
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Place::initWithPosition(const Point& pos) {
|
2013-06-15 14:03:30 +08:00
|
|
|
_position = pos;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Place * Place::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new Place();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->initWithPosition(_position);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Place * Place::reverse() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
|
|
|
// no reverse, just clone
|
|
|
|
return this->clone();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Object * Place::copyWithZone(Zone *pZone) {
|
|
|
|
Zone *pNewZone = NULL;
|
|
|
|
Place *pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (pZone && pZone->_copyObject) {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = (Place*) (pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
} else {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = new Place();
|
|
|
|
pZone = pNewZone = new Zone(pRet);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant::copyWithZone(pZone);
|
2013-06-15 14:03:30 +08:00
|
|
|
pRet->initWithPosition(_position);
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Place::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setPosition(_position);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// CallFunc
|
|
|
|
//
|
2013-06-04 03:13:24 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc * CallFunc::create(const std::function<void()> &func)
|
2013-06-04 03:13:24 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc *pRet = new CallFunc();
|
2013-06-04 03:13:24 +08:00
|
|
|
|
|
|
|
if (pRet && pRet->initWithFunction(func) ) {
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc * CallFunc::create(Object* pSelectorTarget, SEL_CallFunc selector)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc *pRet = new CallFunc();
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet && pRet->initWithTarget(pSelectorTarget)) {
|
2013-06-15 14:03:30 +08:00
|
|
|
pRet->_callFunc = selector;
|
2012-04-19 14:35:52 +08:00
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2011-08-25 19:04:29 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc * CallFunc::create(int nHandler)
|
2012-08-21 18:42:35 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc *pRet = new CallFunc();
|
2012-08-21 18:42:35 +08:00
|
|
|
|
|
|
|
if (pRet) {
|
2013-06-15 14:03:30 +08:00
|
|
|
pRet->_scriptHandler = nHandler;
|
2012-08-21 18:42:35 +08:00
|
|
|
pRet->autorelease();
|
|
|
|
}
|
2012-08-23 16:27:22 +08:00
|
|
|
else{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
return pRet;
|
2012-08-21 18:42:35 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool CallFunc::initWithFunction(const std::function<void()> &func)
|
2013-06-04 03:13:24 +08:00
|
|
|
{
|
|
|
|
_function = func;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool CallFunc::initWithTarget(Object* pSelectorTarget) {
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pSelectorTarget)
|
|
|
|
{
|
|
|
|
pSelectorTarget->retain();
|
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_selectorTarget)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_selectorTarget->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_selectorTarget = pSelectorTarget;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc::~CallFunc(void)
|
2012-12-02 15:01:12 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_scriptHandler)
|
2012-12-02 15:01:12 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
cocos2d::ScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(_scriptHandler);
|
2012-12-02 15:01:12 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_selectorTarget);
|
2012-12-02 15:01:12 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc * CallFunc::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new CallFunc();
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _selectorTarget) {
|
|
|
|
a->initWithTarget(_selectorTarget);
|
|
|
|
a->_callFunc = _callFunc;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
else if( _function )
|
|
|
|
a->initWithFunction(_function);
|
|
|
|
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc * CallFunc::reverse() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
|
|
|
// no reverse here, just return a clone
|
|
|
|
return this->clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Object * CallFunc::copyWithZone(Zone *pZone) {
|
|
|
|
Zone* pNewZone = NULL;
|
|
|
|
CallFunc* pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (pZone && pZone->_copyObject) {
|
2012-04-19 14:35:52 +08:00
|
|
|
//in case of being called at sub class
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = (CallFunc*) (pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
} else {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = new CallFunc();
|
|
|
|
pZone = pNewZone = new Zone(pRet);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInstant::copyWithZone(pZone);
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _selectorTarget) {
|
|
|
|
pRet->initWithTarget(_selectorTarget);
|
|
|
|
pRet->_callFunc = _callFunc;
|
2013-06-04 03:13:24 +08:00
|
|
|
}
|
|
|
|
else if( _function )
|
|
|
|
pRet->initWithFunction(_function);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_scriptHandler > 0 ) {
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet->_scriptHandler = cocos2d::ScriptEngineManager::sharedManager()->getScriptEngine()->reallocateScriptHandler(_scriptHandler);
|
2013-06-05 16:25:23 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void CallFunc::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
|
|
|
this->execute();
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void CallFunc::execute() {
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_callFunc) {
|
|
|
|
(_selectorTarget->*_callFunc)();
|
2013-06-04 03:13:24 +08:00
|
|
|
} else if( _function )
|
|
|
|
_function();
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_scriptHandler) {
|
2013-06-20 14:13:12 +08:00
|
|
|
ScriptEngineManager::sharedManager()->getScriptEngine()->executeCallFuncActionEvent(this);
|
2012-08-21 18:42:35 +08:00
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// CallFuncN
|
|
|
|
//
|
2013-06-22 05:58:52 +08:00
|
|
|
|
|
|
|
CallFuncN * CallFuncN::create(const std::function<void(Node*)> &func)
|
|
|
|
{
|
|
|
|
auto ret = new CallFuncN();
|
|
|
|
|
|
|
|
if (ret && ret->initWithFunction(func) ) {
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-06-22 05:58:52 +08:00
|
|
|
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
return NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
// XXX deprecated
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFuncN * CallFuncN::create(Object* pSelectorTarget, SEL_CallFuncN selector)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFuncN *pRet = new CallFuncN();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-06-14 17:18:05 +08:00
|
|
|
if (pRet && pRet->initWithTarget(pSelectorTarget, selector))
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFuncN * CallFuncN::create(int nHandler)
|
2012-08-21 18:42:35 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFuncN *pRet = new CallFuncN();
|
2012-08-21 18:42:35 +08:00
|
|
|
|
|
|
|
if (pRet) {
|
2013-06-15 14:03:30 +08:00
|
|
|
pRet->_scriptHandler = nHandler;
|
2012-08-21 18:42:35 +08:00
|
|
|
pRet->autorelease();
|
|
|
|
}
|
2012-08-23 16:27:22 +08:00
|
|
|
else{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
return pRet;
|
2012-08-21 18:42:35 +08:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
void CallFuncN::execute() {
|
|
|
|
if (_callFuncN) {
|
|
|
|
(_selectorTarget->*_callFuncN)(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-06-22 05:58:52 +08:00
|
|
|
else if (_functionN) {
|
|
|
|
_functionN(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-06-22 05:58:52 +08:00
|
|
|
if (_scriptHandler) {
|
|
|
|
ScriptEngineManager::sharedManager()->getScriptEngine()->executeCallFuncActionEvent(this, _target);
|
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
bool CallFuncN::initWithFunction(const std::function<void (Node *)> &func)
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-22 05:58:52 +08:00
|
|
|
_functionN = func;
|
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
bool CallFuncN::initWithTarget(Object* pSelectorTarget, SEL_CallFuncN selector)
|
2012-06-14 17:18:05 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (CallFunc::initWithTarget(pSelectorTarget)) {
|
2013-06-22 05:58:52 +08:00
|
|
|
_callFuncN = selector;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return false;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
CallFuncN * CallFuncN::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-22 05:58:52 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new CallFuncN();
|
|
|
|
a->initWithTarget(_selectorTarget, _callFuncN);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
Object * CallFuncN::copyWithZone(Zone* zone)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Zone* pNewZone = NULL;
|
2013-06-22 05:58:52 +08:00
|
|
|
CallFuncN* pRet = NULL;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (zone && zone->_copyObject) {
|
2012-04-19 14:35:52 +08:00
|
|
|
//in case of being called at sub class
|
2013-06-22 05:58:52 +08:00
|
|
|
pRet = (CallFuncN*) (zone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
} else {
|
2013-06-22 05:58:52 +08:00
|
|
|
pRet = new CallFuncN();
|
2013-06-20 14:13:12 +08:00
|
|
|
zone = pNewZone = new Zone(pRet);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CallFunc::copyWithZone(zone);
|
2013-06-22 05:58:52 +08:00
|
|
|
pRet->initWithTarget(_selectorTarget, _callFuncN);
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
|
|
|
NS_CC_END
|