/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc. 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.
****************************************************************************/ #ifndef __ACTIONS_CCACTION_H__
#define __ACTIONS_CCACTION_H__ #include "cocoa/CCObject.h"
#include "cocoa/CCGeometry.h"
#include "platform/CCPlatformMacros.h" NS_CC_BEGIN enum {
//! Default tag
kCCActionTagInvalid = -,
}; /**
* @addtogroup actions
* @{
*/ /**
@brief Base class for CCAction objects.
*/
class CC_DLL CCAction : public CCObject
{
public:
CCAction(void);
virtual ~CCAction(void); const char* description(); virtual CCObject* copyWithZone(CCZone *pZone); //! return true if the action has finished
virtual bool isDone(void); //! called before the action start. It will also set the target.
virtual void startWithTarget(CCNode *pTarget); /**
called after the action has finished. It will set the 'target' to nil.
IMPORTANT: You should never call "[action stop]" manually. Instead, use: "target->stopAction(action);"
*/
virtual void stop(void); //! called every frame with it's delta time. DON'T override unless you know what you are doing.
virtual void step(float dt); /**
called once per frame. time a value between 0 and 1 For example:
- 0 means that the action just started
- 0.5 means that the action is in the middle
- 1 means that the action is over
*/
virtual void update(float time); inline CCNode* getTarget(void) { return m_pTarget; }
/** The action will modify the target properties. */
inline void setTarget(CCNode *pTarget) { m_pTarget = pTarget; } inline CCNode* getOriginalTarget(void) { return m_pOriginalTarget; }
/** Set the original target, since target can be nil.
Is the target that were used to run the action. Unless you are doing something complex, like CCActionManager, you should NOT call this method.
The target is 'assigned', it is not 'retained'.
@since v0.8.2
*/
inline void setOriginalTarget(CCNode *pOriginalTarget) { m_pOriginalTarget = pOriginalTarget; } inline int getTag(void) { return m_nTag; }
inline void setTag(int nTag) { m_nTag = nTag; } public:
/** Create an action */
static CCAction* create();
protected:
CCNode *m_pOriginalTarget;
/** The "target".
The target will be set with the 'startWithTarget' method.
When the 'stop' method is called, target will be set to nil.
The target is 'assigned', it is not 'retained'.
*/
CCNode *m_pTarget;
/** The action tag. An identifier of the action */
int m_nTag;
}; /**
@brief
Base class actions that do have a finite time duration.
Possible actions:
- An action with a duration of 0 seconds
- An action with a duration of 35.5 seconds Infinite time actions are valid
*/
class CC_DLL CCFiniteTimeAction : public CCAction
{
public:
CCFiniteTimeAction()
: m_fDuration()
{}
virtual ~CCFiniteTimeAction(){}
//! get duration in seconds of the action
inline float getDuration(void) { return m_fDuration; }
//! set duration in seconds of the action
inline void setDuration(float duration) { m_fDuration = duration; } /** returns a reversed action */
virtual CCFiniteTimeAction* reverse(void);
protected:
//! duration in seconds
float m_fDuration;
}; class CCActionInterval;
class CCRepeatForever; /**
@brief Changes the speed of an action, making it take longer (speed>1)
or less (speed<1) time.
Useful to simulate 'slow motion' or 'fast forward' effect.
@warning This action can't be Sequenceable because it is not an CCIntervalAction
*/
class CC_DLL CCSpeed : public CCAction
{
public:
CCSpeed()
: m_fSpeed(0.0)
, m_pInnerAction(NULL)
{}
virtual ~CCSpeed(void); inline float getSpeed(void) { return m_fSpeed; }
/** alter the speed of the inner function in runtime */
inline void setSpeed(float fSpeed) { m_fSpeed = fSpeed; } /** initializes the action */
bool initWithAction(CCActionInterval *pAction, float fSpeed); virtual CCObject* copyWithZone(CCZone *pZone);
virtual void startWithTarget(CCNode* pTarget);
virtual void stop();
virtual void step(float dt);
virtual bool isDone(void);
virtual CCActionInterval* reverse(void); void setInnerAction(CCActionInterval *pAction); inline CCActionInterval* getInnerAction()
{
return m_pInnerAction;
} public:
/** create the action */
static CCSpeed* create(CCActionInterval* pAction, float fSpeed);
protected:
float m_fSpeed;
CCActionInterval *m_pInnerAction;
}; /**
@brief CCFollow is an action that "follows" a node. Eg:
layer->runAction(CCFollow::actionWithTarget(hero)); Instead of using CCCamera as a "follower", use this action instead.
@since v0.99.2
*/
class CC_DLL CCFollow : public CCAction
{
public:
CCFollow()
: m_pobFollowedNode(NULL)
, m_bBoundarySet(false)
, m_bBoundaryFullyCovered(false)
, m_fLeftBoundary(0.0)
, m_fRightBoundary(0.0)
, m_fTopBoundary(0.0)
, m_fBottomBoundary(0.0)
{}
virtual ~CCFollow(void); inline bool isBoundarySet(void) { return m_bBoundarySet; }
/** alter behavior - turn on/off boundary */
inline void setBoudarySet(bool bValue) { m_bBoundarySet = bValue; } /** initializes the action with a set boundary */
bool initWithTarget(CCNode *pFollowedNode, const CCRect& rect = CCRectZero); virtual CCObject* copyWithZone(CCZone *pZone);
virtual void step(float dt);
virtual bool isDone(void);
virtual void stop(void); public:
/** creates the action with a set boundary,
It will work with no boundary if @param rect is equal to CCRectZero.
*/
static CCFollow* create(CCNode *pFollowedNode, const CCRect& rect = CCRectZero);
protected:
// node to follow
CCNode *m_pobFollowedNode; // whether camera should be limited to certain area
bool m_bBoundarySet; // if screen size is bigger than the boundary - update not needed
bool m_bBoundaryFullyCovered; // fast access to the screen dimensions
CCPoint m_obHalfScreenSize;
CCPoint m_obFullScreenSize; // world boundaries
float m_fLeftBoundary;
float m_fRightBoundary;
float m_fTopBoundary;
float m_fBottomBoundary;
}; // end of actions group
/// @} NS_CC_END #endif // __ACTIONS_CCACTION_H__
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc. 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 "CCAction.h"
#include "CCActionInterval.h"
#include "base_nodes/CCNode.h"
#include "support/CCPointExtension.h"
#include "CCDirector.h"
#include "cocoa/CCZone.h" NS_CC_BEGIN
//
// Action Base Class
// CCAction::CCAction()
:m_pOriginalTarget(NULL)
,m_pTarget(NULL)
,m_nTag(kCCActionTagInvalid)
{
} CCAction::~CCAction()
{
CCLOGINFO("cocos2d: deallocing");
} CCAction* CCAction::create()
{
CCAction * pRet = new CCAction();
pRet->autorelease();
return pRet;
} const char* CCAction::description()
{
return CCString::createWithFormat("<CCAction | Tag = %d>", m_nTag)->getCString();
} CCObject* CCAction::copyWithZone(CCZone *pZone)
{
CCZone *pNewZone = NULL;
CCAction *pRet = NULL;
if (pZone && pZone->m_pCopyObject)
{
pRet = (CCAction*)(pZone->m_pCopyObject);
}
else
{
pRet = new CCAction();
pNewZone = new CCZone(pRet);
}
//copy member data
pRet->m_nTag = m_nTag;
CC_SAFE_DELETE(pNewZone);
return pRet;
} void CCAction::startWithTarget(CCNode *aTarget)
{
m_pOriginalTarget = m_pTarget = aTarget;
} void CCAction::stop()
{
m_pTarget = NULL;
} bool CCAction::isDone()
{
return true;
} void CCAction::step(float dt)
{
CC_UNUSED_PARAM(dt);
CCLOG("[Action step]. override me");
} void CCAction::update(float time)
{
CC_UNUSED_PARAM(time);
CCLOG("[Action update]. override me");
} //
// FiniteTimeAction
// CCFiniteTimeAction *CCFiniteTimeAction::reverse()
{
CCLOG("cocos2d: FiniteTimeAction#reverse: Implement me");
return NULL;
} //
// Speed
//
CCSpeed::~CCSpeed()
{
CC_SAFE_RELEASE(m_pInnerAction);
} CCSpeed* CCSpeed::create(CCActionInterval* pAction, float fSpeed)
{
CCSpeed *pRet = new CCSpeed();
if (pRet && pRet->initWithAction(pAction, fSpeed))
{
pRet->autorelease();
return pRet;
}
CC_SAFE_DELETE(pRet);
return NULL;
} bool CCSpeed::initWithAction(CCActionInterval *pAction, float fSpeed)
{
CCAssert(pAction != NULL, "");
pAction->retain();
m_pInnerAction = pAction;
m_fSpeed = fSpeed;
return true;
} CCObject *CCSpeed::copyWithZone(CCZone *pZone)
{
CCZone* pNewZone = NULL;
CCSpeed* pRet = NULL;
if(pZone && pZone->m_pCopyObject) //in case of being called at sub class
{
pRet = (CCSpeed*)(pZone->m_pCopyObject);
}
else
{
pRet = new CCSpeed();
pZone = pNewZone = new CCZone(pRet);
}
CCAction::copyWithZone(pZone); pRet->initWithAction( (CCActionInterval*)(m_pInnerAction->copy()->autorelease()) , m_fSpeed ); CC_SAFE_DELETE(pNewZone);
return pRet;
} void CCSpeed::startWithTarget(CCNode* pTarget)
{
CCAction::startWithTarget(pTarget);
m_pInnerAction->startWithTarget(pTarget);
} void CCSpeed::stop()
{
m_pInnerAction->stop();
CCAction::stop();
} void CCSpeed::step(float dt)
{
m_pInnerAction->step(dt * m_fSpeed);
} bool CCSpeed::isDone()
{
return m_pInnerAction->isDone();
} CCActionInterval *CCSpeed::reverse()
{
return (CCActionInterval*)(CCSpeed::create(m_pInnerAction->reverse(), m_fSpeed));
} void CCSpeed::setInnerAction(CCActionInterval *pAction)
{
if (m_pInnerAction != pAction)
{
CC_SAFE_RELEASE(m_pInnerAction);
m_pInnerAction = pAction;
CC_SAFE_RETAIN(m_pInnerAction);
}
} //
// Follow
//
CCFollow::~CCFollow()
{
CC_SAFE_RELEASE(m_pobFollowedNode);
} CCFollow* CCFollow::create(CCNode *pFollowedNode, const CCRect& rect/* = CCRectZero*/)
{
CCFollow *pRet = new CCFollow();
if (pRet && pRet->initWithTarget(pFollowedNode, rect))
{
pRet->autorelease();
return pRet;
}
CC_SAFE_DELETE(pRet);
return NULL;
} bool CCFollow::initWithTarget(CCNode *pFollowedNode, const CCRect& rect/* = CCRectZero*/)
{
CCAssert(pFollowedNode != NULL, ""); pFollowedNode->retain();
m_pobFollowedNode = pFollowedNode;
if (rect.equals(CCRectZero))
{
m_bBoundarySet = false;
}
else
{
m_bBoundarySet = true;
} m_bBoundaryFullyCovered = false; CCSize winSize = CCDirector::sharedDirector()->getWinSize();
m_obFullScreenSize = CCPointMake(winSize.width, winSize.height);
m_obHalfScreenSize = ccpMult(m_obFullScreenSize, 0.5f); if (m_bBoundarySet)
{
m_fLeftBoundary = -((rect.origin.x+rect.size.width) - m_obFullScreenSize.x);
m_fRightBoundary = -rect.origin.x ;
m_fTopBoundary = -rect.origin.y;
m_fBottomBoundary = -((rect.origin.y+rect.size.height) - m_obFullScreenSize.y); if(m_fRightBoundary < m_fLeftBoundary)
{
// screen width is larger than world's boundary width
//set both in the middle of the world
m_fRightBoundary = m_fLeftBoundary = (m_fLeftBoundary + m_fRightBoundary) / ;
}
if(m_fTopBoundary < m_fBottomBoundary)
{
// screen width is larger than world's boundary width
//set both in the middle of the world
m_fTopBoundary = m_fBottomBoundary = (m_fTopBoundary + m_fBottomBoundary) / ;
} if( (m_fTopBoundary == m_fBottomBoundary) && (m_fLeftBoundary == m_fRightBoundary) )
{
m_bBoundaryFullyCovered = true;
}
} return true;
} CCObject *CCFollow::copyWithZone(CCZone *pZone)
{
CCZone *pNewZone = NULL;
CCFollow *pRet = NULL;
if(pZone && pZone->m_pCopyObject) //in case of being called at sub class
{
pRet = (CCFollow*)(pZone->m_pCopyObject);
}
else
{
pRet = new CCFollow();
pZone = pNewZone = new CCZone(pRet);
}
CCAction::copyWithZone(pZone);
// copy member data
pRet->m_nTag = m_nTag;
CC_SAFE_DELETE(pNewZone);
return pRet;
} void CCFollow::step(float dt)
{
CC_UNUSED_PARAM(dt); if(m_bBoundarySet)
{
// whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased
if(m_bBoundaryFullyCovered)
return; CCPoint tempPos = ccpSub( m_obHalfScreenSize, m_pobFollowedNode->getPosition()); m_pTarget->setPosition(ccp(clampf(tempPos.x, m_fLeftBoundary, m_fRightBoundary),
clampf(tempPos.y, m_fBottomBoundary, m_fTopBoundary)));
}
else
{
m_pTarget->setPosition(ccpSub(m_obHalfScreenSize, m_pobFollowedNode->getPosition()));
}
} bool CCFollow::isDone()
{
return ( !m_pobFollowedNode->isRunning() );
} void CCFollow::stop()
{
m_pTarget = NULL;
CCAction::stop();
} NS_CC_END

CCAction、CCFiniteTimeAction、CCSpeed、CCFollow的更多相关文章

  1. .NET 基础 一步步 一幕幕[面向对象之方法、方法的重载、方法的重写、方法的递归]

    方法.方法的重载.方法的重写.方法的递归 方法: 将一堆代码进行重用的一种机制. 语法: [访问修饰符] 返回类型 <方法名>(参数列表){ 方法主体: } 返回值类型:如果不需要写返回值 ...

  2. JavaScript学习笔记(一)——延迟对象、跨域、模板引擎、弹出层、AJAX示例

    一.AJAX示例 AJAX全称为“Asynchronous JavaScript And XML”(异步JavaScript和XML) 是指一种创建交互式网页应用的开发技术.改善用户体验,实现无刷新效 ...

  3. atitit.管理学三大定律:彼得原理、墨菲定律、帕金森定律

    atitit.管理学三大定律:彼得原理.墨菲定律.帕金森定律 彼得原理(The Peter Principle) 1 彼得原理解决方案1 帕金森定律 2 如何理解墨菲定律2 彼得原理(The Pete ...

  4. 【完全开源】知乎日报UWP版(下篇):商店APP、github源码、功能说明。Windows APP 良心出品。

    目录 说明 功能 截图+视频 关于源码和声明 说明 陆陆续续大概花了一个月的时间,APP算是基本完成了.12月份一直在外出差,在出差期间进行了两次功能完善,然后断断续续修补了一些bug,到目前为止,我 ...

  5. Windows Server 2012 磁盘管理之 简单卷、跨区卷、带区卷、镜像卷和RAID-5卷

    今天给客户配置故障转移群集,在Windows Server 2012 R2的系统上,通过iSCSI连接上DELL的SAN存储后,在磁盘管理里面发现可以新建 简单卷.跨区卷.带区卷.镜像卷.RAID-5 ...

  6. react+redux教程(五)异步、单一state树结构、componentWillReceiveProps

    今天,我们要讲解的是异步.单一state树结构.componentWillReceiveProps这三个知识点. 例子 这个例子是官方的例子,主要是从Reddit中请求新闻列表来显示,可以切换reac ...

  7. 记2016腾讯 TST 校招面试经历,电面、笔试写代码、技术面、hr面,共5轮

    (出处:http://www.cnblogs.com/linguanh/) 前序: 距离  2016 腾讯 TST 校招面试结束已经5天了,3月27日至今,目前还在等待消息.从投简历到两轮电面,再到被 ...

  8. JavaScript学习总结(一)——延迟对象、跨域、模板引擎、弹出层、AJAX示例

    一.AJAX示例 AJAX全称为“Asynchronous JavaScript And XML”(异步JavaScript和XML) 是指一种创建交互式网页应用的开发技术.改善用户体验,实现无刷新效 ...

  9. CSS3与页面布局学习总结(二)——Box Model、边距折叠、内联与块标签、CSSReset

    一.盒子模型(Box Model) 盒子模型也有人称为框模型,HTML中的多数元素都会在浏览器中生成一个矩形的区域,每个区域包含四个组成部分,从外向内依次是:外边距(Margin).边框(Border ...

随机推荐

  1. .NET(C#):警惕PLINQ结果的无序性

    .NET(C#):警惕PLINQ结果的无序性 2012年08月10日 ⁄ 综合 ⁄ 共 620字 ⁄ 字号 小 中 大 ⁄ 评论关闭   PLINQ的运行结果是无序的,也就是不保持原来集合的顺序来操作 ...

  2. weblogic安装错误BEA-090870解决方案

    00.问题描述 <Sep 3, 2017 3:29:09 PM CST> <Error> <Security> <BEA-090870> <The ...

  3. rac安装_grid安装校验报错之grid未建立信任关系

    原创作品,出自 "深蓝的blog" 博客,欢迎转载,转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlo ...

  4. windows常用命令行整理

    Windows虽然以GUI界面为主,但有时命令行也起到了很大的作用,下面就介绍几个常用.常见的windows命令行命令 1.ping 功能:用来测试数据包能否通过IP协议到达特定主机.即测试本机与特定 ...

  5. Linux-内核态与用户态

    内核态: CPU可以访问内存所有数据, 包括外围设备, 例如硬盘, 网卡. CPU也可以将自己从一个程序切换到另一个程序 用户态: 只能受限的访问内存, 且不允许访问外围设备. 占用CPU的能力被剥夺 ...

  6. 【RS】Amazon.com recommendations: item-to-item collaborative filtering - 亚马逊推荐:基于物品的协同过滤

    [论文标题]Amazon.com recommendations: item-to-item collaborative filtering (2003,Published by the IEEE C ...

  7. MATLAB R2018a 输入中文却显示方框问号的问题

    [问题] 安装完成软件后,我把编辑区字体重设为 consolas : 就会出现 输入中文注释却没办法正常显示的问题: [解决办法] 把字体改成 Monospaced (查了一下 说是MATLAB默认字 ...

  8. winetricks 用WineTricks令你的Wine更完整

    Linux下最有名的Windows环境模拟器就是WINE了.它提供了一个可以模拟WINDOWS环境的基本平台,在这上面你几乎可以运行任何你想运行的windows程序. 什么?你不相信?不要告诉我你的程 ...

  9. Ubuntu菜鸟入门(十)—— Flash控件安装

    一.用firefox打开视频时发现,ubuntu并没有自带flash插件,所以流媒体视频无法正常播放,为了解决这个问题,这里我们需要来安装Adobe® Flash® Player插件,这是一款轻量级浏 ...

  10. golang学习笔记 ---命令行参数

    os 包以跨平台的方式,提供了一些与操作系统交互的函数和变量.程序的命令行参数可从os包的Args变量获取:os包外部使用os.Args访问该变量. os.Args变量是一个字符串(string)的切 ...