cocos2d-X 节点(CCMotionStreak.h)API
2013-11-08 21:09
495 查看
本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
在游戏的实现过程中,有时会需要在某个游戏对象上的运动轨迹上实现渐隐效果。这种感觉就好像是类似飞机拉线的拖尾巴,在视觉上感觉很好,比如子弹的运动轨迹等,如果不借助引擎的帮助,这种效果往往需要通过大量的图片来实现。而Cocos2D-x提供了一种内置的拖动渐隐效果类CCMotionStreak来帮助我们实现这个效果。
cocos2d-X 节点(CCMotionStreak.h)API
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记在游戏的实现过程中,有时会需要在某个游戏对象上的运动轨迹上实现渐隐效果。这种感觉就好像是类似飞机拉线的拖尾巴,在视觉上感觉很好,比如子弹的运动轨迹等,如果不借助引擎的帮助,这种效果往往需要通过大量的图片来实现。而Cocos2D-x提供了一种内置的拖动渐隐效果类CCMotionStreak来帮助我们实现这个效果。
///cocos2d-x-3.0alpha0/cocos2dx/actions #ifndef __ACTIONS_CCACTION_H__ #define __ACTIONS_CCACTION_H__ #include "cocoa/CCObject.h" #include "cocoa/CCGeometry.h" #include "platform/CCPlatformMacros.h" NS_CC_BEGIN /** * @addtogroup actions * @{ */ /** @brief Action 对象的基础类. */ class CC_DLL Action : public Object, public Clonable { public: /// 所有 action 默认使用的标签 static const int INVALID_TAG = -1; /** * @js ctor */ Action(void); /** * @js NA * @lua NA */ virtual ~Action(void); /** * @js NA * @lua NA */ const char* description() const; /** returns 一个克隆的 action */ virtual Action* clone() const = 0; /** returns 一个新的 action 执行完全相反的动作 */ virtual Action* reverse() const = 0; //! return true 如果 action 结束了 virtual bool isDone(void) const; //! 启动前调用. 他也会设置 target. virtual void startWithTarget(Node *target); /** action结束时调用. 塌毁设置 'target' 为 nil. IMPORTANT: 你应该永远不要手动调用 "[action stop]" . 可以使用: "target->stopAction(action);代替" */ virtual void stop(void); //! 每一个时间间隔都会刷帧,除非你知道你在做什么否则不要覆盖它. virtual void step(float dt); /** 每一帧都会调用. 时间值在 0 和 1 之间 For example: - 0 意味着 action 即将开始 - 0.5 意味着 action 执行了一半 - 1 意味着 action 执行完了 */ virtual void update(float time); inline Node* getTarget(void) const { return _target; } /** 该 action将修改 target 属性. */ inline void setTarget(Node *target) { _target = target; } inline Node* getOriginalTarget(void) const { return _originalTarget; } /** target 为 nil 时设置原始的 target 这个 target 是我们用于执行的 action,除非你是做一些复杂的事情,例如管理 action 否则你不应该调用这个方法 target 已经 'assigned'(分配), 但是还没有 'retained'(保留). @since v0.8.2 */ inline void setOriginalTarget(Node *pOriginalTarget) { _originalTarget = pOriginalTarget; } inline int getTag(void) const { return _tag; } inline void setTag(int nTag) { _tag = nTag; } protected: Node *_originalTarget; /** The "target". target 将使用 'startWithTarget' 方法设置. 当 'stop' 方法调用后, target 将设置为 nil. target 已经 'assigned'(分配), 但是还没有 'retained'(保留). */ Node *_target; /** action 标签. action 的识别标记 */ int _tag; }; /** @brief action 的基础类,他有一个有限的动作持续时间 Possible actions: - 一个动作的持续时间为 0 秒 - 一个动作的持续时间为 35.5 秒 无穷大时间的行动是有效的 */ class CC_DLL FiniteTimeAction : public Action { public: /** * @js ctor */ FiniteTimeAction() : _duration(0) {} /** * @js NA * @lua NA */ virtual ~FiniteTimeAction(){} //! get 这个 action 的持续时间(秒) inline float getDuration(void) const { return _duration; } //! set 这个 action 的持续时间(秒) inline void setDuration(float duration) { _duration = duration; } // // Overrides // virtual FiniteTimeAction* reverse() const override = 0; virtual FiniteTimeAction* clone() const override = 0; protected: //!持续时间(秒) float _duration; }; class ActionInterval; class RepeatForever; /** @brief 改变素的的 action, m创建他需要多少时间 (speed>1) or less (speed<1) time. 模拟 'slow motion'(慢动作) or 'fast forward'(快进) 效果时是非常有用的. @warning 这个 action不能 Sequenceable(预测控制) 因为他不是一个 IntervalAction(间隔 actton) */ class CC_DLL Speed : public Action { public: /** create the action */ static Speed* create(ActionInterval* pAction, float fSpeed); /** * @js ctor */ Speed(); /** * @js NA * @lua NA */ virtual ~Speed(void); inline float getSpeed(void) const { return _speed; } /** 内部功能改变这个 action 的 runtime(运行时间) */ inline void setSpeed(float fSpeed) { _speed = fSpeed; } /** 初始化 action */ bool initWithAction(ActionInterval *pAction, float fSpeed); void setInnerAction(ActionInterval *pAction); inline ActionInterval* getInnerAction() const { return _innerAction; } // // Override // virtual Speed* clone() const override; virtual Speed* reverse() const override; virtual void startWithTarget(Node* target) override; virtual void stop() override; virtual void step(float dt) override; virtual bool isDone(void) const override; protected: float _speed; ActionInterval *_innerAction; }; /** @brief action 执行完后,紧随其后的节点 Eg: @code layer->runAction(Follow::actionWithTarget(hero)); @endcode 代替使用 Camera 作为紧随其后的节点, 使用这个 action 代替. @since v0.99.2 */ class CC_DLL Follow : public Action { public: /** * 创建一个有边界或无边界的行动 * * @param followedNode 这个节点将在随后启用 * @param rect 边界. 如果 rect equal(等于) Rect::ZERO, i他会创建一个没有边界的动作 */ static Follow* create(Node *followedNode, const Rect& rect = Rect::ZERO); /** * @js ctor */ Follow() : _followedNode(NULL) , _boundarySet(false) , _boundaryFullyCovered(false) , _leftBoundary(0.0) , _rightBoundary(0.0) , _topBoundary(0.0) , _bottomBoundary(0.0) , _worldRect(Rect::ZERO) {} /** * @js NA * @lua NA */ virtual ~Follow(void); inline bool isBoundarySet(void) const { return _boundarySet; } /** 改变动作 - 改变成 有/无 边界 */ inline void setBoudarySet(bool bValue) { _boundarySet = bValue; } /** * 初始化一个有边界或无边界的行动 * * @param followedNode 这个节点将在随后启用 * @param rect 边界. 如果 rect equal(等于) Rect::ZERO, i他会创建一个没有边界的动作 */ bool initWithTarget(Node *followedNode, const Rect& rect = Rect::ZERO); // // Override // virtual Follow* clone() const override; virtual Follow* reverse() const override; virtual void step(float dt) override; virtual bool isDone(void) const override; virtual void stop(void) override; protected: // 紧随其后的 node Node *_followedNode; // 是否把 camera(视角)限制在一个确定的区域 bool _boundarySet; // 如果 screen(快照)尺寸大于边界 - 不需要更新 bool _boundaryFullyCovered; // 快速使用 screen(快照) 尺寸 Point _halfScreenSize; Point _fullScreenSize; // world boundaries //边界线 float _leftBoundary; float _rightBoundary; float _topBoundary; float _bottomBoundary; Rect _worldRect; }; // end of actions group /// @} NS_CC_END #endif // __ACTIONS_CCACTION_H__
相关文章推荐
- cocos2d-x节点(CCPhysicsShape.h)API
- cocos2d-x节点(CCActionTween.h)API
- cocos2d-X 节点(CCMenuItem.h)API
- cocos2d-x节点(CCPhysicsJoint.h)API
- cocos2d-x节点(CCPhysicsWorld.h)API
- cocos2d-x节点(CCVertex.h)API
- cocos2d-x节点(CCApplicationProtocol.h)API
- cocos2d-x节点(CCPhysicsSetting.h)API
- cocos2d-x CCMotionStreak 拖拽渐隐效果(切水果的刀?)
- cocos2d-x节点(CCCommon.h)API
- cocos2d-x节点(CCTransitionProgress.h)API
- cocos2d-X 节点(CCActionFrameEasing.h)API
- cocos2d-x节点(CCTransitionPageTurn.h)API
- cocos2d-x节点(CCEvent.h)API
- cocos2d-X 节点(CCActionFrame.h)API
- cocos2d-x节点(CCClippingNode.h)API
- cocos2d-x节点(CCEventListener.h)API
- cocos2d-x节点(CCActionCamera.h)API
- COcos2d-X 节点(CCGLBufferedNode.h)API
- cocos2d-X 节点(CCCamera.h.)API