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-14 08:25:14 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
bool CCActionInstant::isDone() {
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCActionInstant::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
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCActionInstant::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
|
|
|
|
|
|
|
CCShow* CCShow::create()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCShow* pRet = new CCShow();
|
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
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCShow::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
2012-06-15 15:10:40 +08:00
|
|
|
m_pTarget->setVisible(true);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
CCActionInstant* CCShow::reverse() const
|
|
|
|
{
|
|
|
|
return CCHide::create();
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCShow * CCShow::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCShow(*this);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject* CCShow::copyWithZone(CCZone *pZone) {
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCShow *pRet = NULL;
|
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCShow*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCShow();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-05-30 16:34:42 +08:00
|
|
|
CCActionInstant::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
|
|
|
|
//
|
2012-06-14 17:18:05 +08:00
|
|
|
CCHide * CCHide::create()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCHide *pRet = new CCHide();
|
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
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCHide::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
2012-06-15 15:10:40 +08:00
|
|
|
m_pTarget->setVisible(false);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
CCActionInstant *CCHide::reverse() const
|
|
|
|
{
|
|
|
|
return CCShow::create();
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCHide * CCHide::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCHide(*this);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject* CCHide::copyWithZone(CCZone *pZone) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCHide *pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCHide*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCHide();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-05-30 16:34:42 +08:00
|
|
|
CCActionInstant::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
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
CCToggleVisibility * CCToggleVisibility::create()
|
2012-05-30 16:34:42 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCToggleVisibility *pRet = new CCToggleVisibility();
|
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
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCToggleVisibility::update(float time)
|
2012-05-30 16:34:42 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
2012-06-15 15:10:40 +08:00
|
|
|
m_pTarget->setVisible(!m_pTarget->isVisible());
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
CCToggleVisibility * CCToggleVisibility::reverse() const
|
|
|
|
{
|
|
|
|
return CCToggleVisibility::create();
|
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCToggleVisibility * CCToggleVisibility::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCToggleVisibility(*this);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2012-05-30 16:34:42 +08:00
|
|
|
CCObject* CCToggleVisibility::copyWithZone(CCZone *pZone)
|
|
|
|
{
|
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCToggleVisibility *pRet = NULL;
|
|
|
|
|
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCToggleVisibility*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCToggleVisibility();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCActionInstant::copyWithZone(pZone);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-03-25 11:10:51 +08:00
|
|
|
//
|
|
|
|
// Remove Self
|
|
|
|
//
|
2013-03-25 18:18:38 +08:00
|
|
|
CCRemoveSelf * CCRemoveSelf::create(bool isNeedCleanUp /*= true*/)
|
2013-03-25 11:10:51 +08:00
|
|
|
{
|
|
|
|
CCRemoveSelf *pRet = new CCRemoveSelf();
|
|
|
|
|
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-03-25 18:18:38 +08:00
|
|
|
bool CCRemoveSelf::init(bool isNeedCleanUp) {
|
|
|
|
m_bIsNeedCleanUp = isNeedCleanUp;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-25 11:10:51 +08:00
|
|
|
void CCRemoveSelf::update(float time) {
|
|
|
|
CC_UNUSED_PARAM(time);
|
2013-03-25 18:18:38 +08:00
|
|
|
m_pTarget->removeFromParentAndCleanup(m_bIsNeedCleanUp);
|
2013-03-25 11:10:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
CCRemoveSelf *CCRemoveSelf::reverse() const
|
|
|
|
{
|
|
|
|
return CCRemoveSelf::create(m_bIsNeedCleanUp);
|
2013-03-25 11:10:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCRemoveSelf * CCRemoveSelf::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCRemoveSelf(*this);
|
|
|
|
a->init(m_bIsNeedCleanUp);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-03-25 11:10:51 +08:00
|
|
|
CCObject* CCRemoveSelf::copyWithZone(CCZone *pZone) {
|
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCRemoveSelf *pRet = NULL;
|
|
|
|
|
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCRemoveSelf*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCRemoveSelf();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCActionInstant::copyWithZone(pZone);
|
2013-03-25 18:18:38 +08:00
|
|
|
pRet->init(m_bIsNeedCleanUp);
|
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
|
|
|
|
|
|
|
CCFlipX *CCFlipX::create(bool x)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCFlipX *pRet = new CCFlipX();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool CCFlipX::initWithFlipX(bool x) {
|
2012-04-19 14:35:52 +08:00
|
|
|
m_bFlipX = x;
|
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCFlipX::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
|
|
|
((CCSprite*) (m_pTarget))->setFlipX(m_bFlipX);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
CCFlipX* CCFlipX::reverse() const
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
return CCFlipX::create(!m_bFlipX);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCFlipX * CCFlipX::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCFlipX(*this);
|
|
|
|
a->initWithFlipX(m_bFlipX);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject * CCFlipX::copyWithZone(CCZone *pZone) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCFlipX *pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCFlipX*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCFlipX();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
2011-08-25 19:04:29 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
|
|
|
pRet->initWithFlipX(m_bFlipX);
|
|
|
|
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
|
|
|
|
|
|
|
CCFlipY * CCFlipY::create(bool y)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCFlipY *pRet = new CCFlipY();
|
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
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
bool CCFlipY::initWithFlipY(bool y) {
|
2012-04-19 14:35:52 +08:00
|
|
|
m_bFlipY = y;
|
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCFlipY::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
|
|
|
((CCSprite*) (m_pTarget))->setFlipY(m_bFlipY);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
CCFlipY* CCFlipY::reverse() const
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
return CCFlipY::create(!m_bFlipY);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCFlipY * CCFlipY::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCFlipY(*this);
|
|
|
|
a->initWithFlipY(m_bFlipY);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject* CCFlipY::copyWithZone(CCZone *pZone) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCFlipY *pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCFlipY*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCFlipY();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
|
|
|
pRet->initWithFlipY(m_bFlipY);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Place
|
|
|
|
//
|
2012-06-14 17:18:05 +08:00
|
|
|
|
|
|
|
CCPlace* CCPlace::create(const CCPoint& pos)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCPlace *pRet = new CCPlace();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool CCPlace::initWithPosition(const CCPoint& pos) {
|
2012-04-19 14:35:52 +08:00
|
|
|
m_tPosition = pos;
|
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCPlace * CCPlace::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCPlace(*this);
|
|
|
|
a->initWithPosition(m_tPosition);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject * CCPlace::copyWithZone(CCZone *pZone) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CCZone *pNewZone = NULL;
|
|
|
|
CCPlace *pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
pRet = (CCPlace*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCPlace();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
|
|
|
pRet->initWithPosition(m_tPosition);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCPlace::update(float time) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_UNUSED_PARAM(time);
|
|
|
|
m_pTarget->setPosition(m_tPosition);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// CallFunc
|
|
|
|
//
|
2013-06-04 03:13:24 +08:00
|
|
|
|
|
|
|
CCCallFunc * CCCallFunc::create(const std::function<void()> &func)
|
|
|
|
{
|
|
|
|
CCCallFunc *pRet = new CCCallFunc();
|
|
|
|
|
|
|
|
if (pRet && pRet->initWithFunction(func) ) {
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-14 17:18:05 +08:00
|
|
|
CCCallFunc * CCCallFunc::create(CCObject* pSelectorTarget, SEL_CallFunc selector)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCCallFunc *pRet = new CCCallFunc();
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet && pRet->initWithTarget(pSelectorTarget)) {
|
|
|
|
pRet->m_pCallFunc = selector;
|
|
|
|
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
|
|
|
|
2012-08-21 18:42:35 +08:00
|
|
|
CCCallFunc * CCCallFunc::create(int nHandler)
|
|
|
|
{
|
|
|
|
CCCallFunc *pRet = new CCCallFunc();
|
|
|
|
|
|
|
|
if (pRet) {
|
|
|
|
pRet->m_nScriptHandler = nHandler;
|
|
|
|
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-04 03:13:24 +08:00
|
|
|
bool CCCallFunc::initWithFunction(const std::function<void()> &func)
|
|
|
|
{
|
|
|
|
_function = func;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
bool CCCallFunc::initWithTarget(CCObject* pSelectorTarget) {
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pSelectorTarget)
|
|
|
|
{
|
|
|
|
pSelectorTarget->retain();
|
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_pSelectorTarget)
|
|
|
|
{
|
|
|
|
m_pSelectorTarget->release();
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pSelectorTarget = pSelectorTarget;
|
|
|
|
return true;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-12-02 15:01:12 +08:00
|
|
|
CCCallFunc::~CCCallFunc(void)
|
|
|
|
{
|
|
|
|
if (m_nScriptHandler)
|
|
|
|
{
|
|
|
|
cocos2d::CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nScriptHandler);
|
|
|
|
}
|
|
|
|
CC_SAFE_RELEASE(m_pSelectorTarget);
|
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCCallFunc * CCCallFunc::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCCallFunc(*this);
|
|
|
|
if( m_pSelectorTarget) {
|
|
|
|
a->initWithTarget(m_pSelectorTarget);
|
|
|
|
a->m_pCallFunc = m_pCallFunc;
|
|
|
|
}
|
|
|
|
else if( _function )
|
|
|
|
a->initWithFunction(_function);
|
|
|
|
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject * CCCallFunc::copyWithZone(CCZone *pZone) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
CCCallFunc* pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pZone && pZone->m_pCopyObject) {
|
|
|
|
//in case of being called at sub class
|
|
|
|
pRet = (CCCallFunc*) (pZone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCCallFunc();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCActionInstant::copyWithZone(pZone);
|
2013-06-04 03:13:24 +08:00
|
|
|
if( m_pSelectorTarget) {
|
|
|
|
pRet->initWithTarget(m_pSelectorTarget);
|
|
|
|
pRet->m_pCallFunc = m_pCallFunc;
|
|
|
|
}
|
|
|
|
else if( _function )
|
|
|
|
pRet->initWithFunction(_function);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCCallFunc::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
|
|
|
}
|
|
|
|
|
|
|
|
void CCCallFunc::execute() {
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_pCallFunc) {
|
|
|
|
(m_pSelectorTarget->*m_pCallFunc)();
|
2013-06-04 03:13:24 +08:00
|
|
|
} else if( _function )
|
|
|
|
_function();
|
2012-08-21 18:42:35 +08:00
|
|
|
if (m_nScriptHandler) {
|
2012-09-11 14:02:33 +08:00
|
|
|
CCScriptEngineManager::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
|
|
|
|
//
|
|
|
|
void CCCallFuncN::execute() {
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_pCallFuncN) {
|
|
|
|
(m_pSelectorTarget->*m_pCallFuncN)(m_pTarget);
|
|
|
|
}
|
2012-08-21 18:42:35 +08:00
|
|
|
if (m_nScriptHandler) {
|
2012-09-11 14:02:33 +08:00
|
|
|
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeCallFuncActionEvent(this, m_pTarget);
|
2012-08-21 18:42:35 +08:00
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-06-14 17:18:05 +08:00
|
|
|
CCCallFuncN * CCCallFuncN::create(CCObject* pSelectorTarget, SEL_CallFuncN selector)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCCallFuncN *pRet = new CCCallFuncN();
|
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
|
|
|
}
|
|
|
|
|
2012-08-21 18:42:35 +08:00
|
|
|
CCCallFuncN * CCCallFuncN::create(int nHandler)
|
|
|
|
{
|
|
|
|
CCCallFuncN *pRet = new CCCallFuncN();
|
|
|
|
|
|
|
|
if (pRet) {
|
|
|
|
pRet->m_nScriptHandler = nHandler;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
bool CCCallFuncN::initWithTarget(CCObject* pSelectorTarget,
|
2012-04-19 14:35:52 +08:00
|
|
|
SEL_CallFuncN selector) {
|
|
|
|
if (CCCallFunc::initWithTarget(pSelectorTarget)) {
|
|
|
|
m_pCallFuncN = selector;
|
|
|
|
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
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCCallFuncN * CCCallFuncN::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCCallFuncN(*this);
|
|
|
|
a->initWithTarget(m_pSelectorTarget, m_pCallFuncN);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject * CCCallFuncN::copyWithZone(CCZone* zone) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
CCCallFuncN* pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (zone && zone->m_pCopyObject) {
|
|
|
|
//in case of being called at sub class
|
|
|
|
pRet = (CCCallFuncN*) (zone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCCallFuncN();
|
|
|
|
zone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCCallFunc::copyWithZone(zone);
|
|
|
|
pRet->initWithTarget(m_pSelectorTarget, m_pCallFuncN);
|
|
|
|
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
|
|
|
//
|
|
|
|
// CallFuncND
|
|
|
|
//
|
2012-06-14 17:18:05 +08:00
|
|
|
|
|
|
|
CCCallFuncND * CCCallFuncND::create(CCObject* pSelectorTarget, SEL_CallFuncND selector, void* d)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCCallFuncND* pRet = new CCCallFuncND();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet && pRet->initWithTarget(pSelectorTarget, selector, d)) {
|
|
|
|
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
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
bool CCCallFuncND::initWithTarget(CCObject* pSelectorTarget,
|
2012-04-19 14:35:52 +08:00
|
|
|
SEL_CallFuncND selector, void* d) {
|
|
|
|
if (CCCallFunc::initWithTarget(pSelectorTarget)) {
|
|
|
|
m_pData = d;
|
|
|
|
m_pCallFuncND = selector;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCCallFuncND * CCCallFuncND::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCCallFuncND(*this);
|
|
|
|
a->initWithTarget(m_pSelectorTarget, m_pCallFuncND, m_pData);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject * CCCallFuncND::copyWithZone(CCZone* zone) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
CCCallFuncND* pRet = NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (zone && zone->m_pCopyObject) {
|
|
|
|
//in case of being called at sub class
|
|
|
|
pRet = (CCCallFuncND*) (zone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCCallFuncND();
|
|
|
|
zone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCCallFunc::copyWithZone(zone);
|
|
|
|
pRet->initWithTarget(m_pSelectorTarget, m_pCallFuncND, m_pData);
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCCallFuncND::execute() {
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_pCallFuncND) {
|
|
|
|
(m_pSelectorTarget->*m_pCallFuncND)(m_pTarget, m_pData);
|
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
//
|
|
|
|
// CCCallFuncO
|
|
|
|
//
|
|
|
|
CCCallFuncO::CCCallFuncO() :
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pObject(NULL) {
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCCallFuncO::~CCCallFuncO() {
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_RELEASE(m_pObject);
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
void CCCallFuncO::execute() {
|
2012-04-19 14:35:52 +08:00
|
|
|
if (m_pCallFuncO) {
|
|
|
|
(m_pSelectorTarget->*m_pCallFuncO)(m_pObject);
|
|
|
|
}
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-06-14 17:18:05 +08:00
|
|
|
CCCallFuncO * CCCallFuncO::create(CCObject* pSelectorTarget, SEL_CallFuncO selector, CCObject* pObject)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCCallFuncO *pRet = new CCCallFuncO();
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet && pRet->initWithTarget(pSelectorTarget, selector, pObject)) {
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
2011-06-20 17:31:38 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
2011-09-05 10:12:14 +08:00
|
|
|
}
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
bool CCCallFuncO::initWithTarget(CCObject* pSelectorTarget,
|
2012-04-19 14:35:52 +08:00
|
|
|
SEL_CallFuncO selector, CCObject* pObject) {
|
|
|
|
if (CCCallFunc::initWithTarget(pSelectorTarget)) {
|
|
|
|
m_pObject = pObject;
|
|
|
|
CC_SAFE_RETAIN(m_pObject);
|
2011-08-24 14:21:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pCallFuncO = selector;
|
|
|
|
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-14 08:25:14 +08:00
|
|
|
CCCallFuncO * CCCallFuncO::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCCallFuncO(*this);
|
|
|
|
a->initWithTarget(m_pSelectorTarget, m_pCallFuncO, m_pObject);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:12:14 +08:00
|
|
|
CCObject * CCCallFuncO::copyWithZone(CCZone* zone) {
|
2012-04-19 14:35:52 +08:00
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
CCCallFuncO* pRet = NULL;
|
|
|
|
|
|
|
|
if (zone && zone->m_pCopyObject) {
|
|
|
|
//in case of being called at sub class
|
|
|
|
pRet = (CCCallFuncO*) (zone->m_pCopyObject);
|
|
|
|
} else {
|
|
|
|
pRet = new CCCallFuncO();
|
|
|
|
zone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCCallFunc::copyWithZone(zone);
|
|
|
|
pRet->initWithTarget(m_pSelectorTarget, m_pCallFuncO, m_pObject);
|
|
|
|
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
|