CCActionGird源码分析
来源:互联网 发布:数据备份器 编辑:程序博客网 时间:2024/06/06 03:59
这个文件中是一些网格动作,网格动作的效果还是可以的,但是,网格动作对效率的影响也是十分明显的,之前用网格动作代替怪兽死亡的动画,一两只还好,当有大批怪兽死亡的时候,效率就十分低了。所以,网格动作可能不太适合同时有太多对象执行。
代码:
/** @class GridAction@brief Base class for Grid actions.@details Grid actions are the actions take effect on GridBase.*//// 格子动作/// 网格动作是影响网格基类的动作,///之前用过一个碎片的效果,当然,那是2.x的时候,///只有一个对象执行的时候,效率还是可以的,但是,对象增多的时候,手机就开始卡了。/// 所以,这种特效类的动作不宜大范围的使用,如果,你不在乎执行效率的话,那就另说了。class CC_DLL GridAction : public ActionInterval/// 又是一个瞬时动作的子类{public: /** @brief Get the pointer of GridBase. @return The pointer of GridBase. *//// 返回GridBase的指针 virtual GridBase* getGrid(); // overrides/// 这些方法都是从Action继承过来的,就不用多说了吧!! virtual GridAction * clone() const override { CC_ASSERT(0); return nullptr; } virtual GridAction* reverse() const override; virtual void startWithTarget(Node *target) override;CC_CONSTRUCTOR_ACCESS: GridAction() {} virtual ~GridAction() {} /** * @brief Initializes the action with size and duration. * @param duration The duration of the GridAction. It's a value in seconds. * @param gridSize The size of the GridAction should be. * @return Return true when the initialization success, otherwise return false. */ /// 初始化 bool initWithDuration(float duration, const Size& gridSize);protected: Size _gridSize; NodeGrid* _gridNodeTarget; /// 将目标转化为BaseGird类型,这个函数就是一个强制类型转换 void cacheTargetAsGridNode();private: CC_DISALLOW_COPY_AND_ASSIGN(GridAction);};/** @brief Base class for Grid3D actions. @details Grid3D actions can modify a non-tiled grid. */ /// 3D网格动作的基类class CC_DLL Grid3DAction : public GridAction{public:/// 得到网格基类 virtual GridBase* getGrid() override; /** * @brief Get the vertex that belongs to certain position in the grid. * @param position The position of the grid. * @return Return a pointer of vertex. * @js vertex * @lua NA */ /// 返回属于网格中某个确定位置的顶点 Vec3 getVertex(const Vec2& position) const; /** @deprecated Use getVertex() instead * @js NA * @lua NA */ /// 废弃的方法 用上面的方法代替了 CC_DEPRECATED_ATTRIBUTE inline Vec3 vertex(const Vec2& position) { return getVertex(position); } /** * @brief Get the non-transformed vertex that belongs to certain position in the grid. * @param position The position of the grid. * @return Return a pointer of vertex. * @js originalVertex * @lua NA */ /// 得到属于网格中某个确定位置的非转化顶点 Vec3 getOriginalVertex(const Vec2& position) const; /** @deprecated Use getOriginalVertex() instead * @js NA * @lua NA */ /// 废弃了 CC_DEPRECATED_ATTRIBUTE inline Vec3 originalVertex(const Vec2& position) { return getOriginalVertex(position); } /** * @brief Set a new vertex to a certain position of the grid. * @param position The position of the grid. * @param vertex The vertex will be used on the certain position of grid. * @js setVertex * @lua NA */ /// 设置属于网格中某个确定位置的顶点 void setVertex(const Vec2& position, const Vec3& vertex); // Overrides virtual Grid3DAction * clone() const override { CC_ASSERT(0); return nullptr; }};/**@brief Base class for TiledGrid3D actions.*//// 3D瓦片网格动画class CC_DLL TiledGrid3DAction : public GridAction{public: /** * @brief Create the action with size and duration. * @param duration The duration of the action. It's a value in seconds. * @param gridSize Specify the grid size of the action. * @return A pointer of TiledGrid3DAction. If creation failed, return nil. * @lua NA */ /// 创建一个3D瓦片网格动画 static TiledGrid3DAction* create(float duration, const Size& gridSize); /** * @brief Get the tile that belongs to a certain position of the grid. * @param position The position of the tile want to get. * @return A quadrilateral of the tile. * @js tile * @lua NA */ /// 返回属于网格的某个确定位置的瓦片 Quad3 getTile(const Vec2& position) const; /** @deprecated Use getTile() instead * @js NA * @lua NA */ /// 废弃了 CC_DEPRECATED_ATTRIBUTE Quad3 tile(const Vec2& position) { return getTile(position); } /** * @brief Get the non-transformed tile that belongs to a certain position of the grid. * @param position The position of the tile want to get. * @return A quadrilateral of the tile. * @js originalTile * @lua NA */ /// 返回属于网格的某个确定位置的未变化的瓦片 Quad3 getOriginalTile(const Vec2& position) const; /** @deprecated Use getOriginalTile() instead. * @js NA * @lua NA */ /// 废弃 CC_DEPRECATED_ATTRIBUTE Quad3 originalTile(const Vec2& position) { return getOriginalTile(position); } /** * @brief Set a new tile to a certain position of the grid. * @param position The position of the tile. * @param coords The quadrilateral of the new tile. * @lua NA */ /// 为网格的某个位置设置一个瓦片 void setTile(const Vec2& position, const Quad3& coords); /** returns the grid */ virtual GridBase* getGrid() override; // Override virtual TiledGrid3DAction * clone() const override { CC_ASSERT(0); return nullptr; }};/**@brief AccelDeccelAmplitude action.@js NA*//// 逐渐加快的振幅动作class CC_DLL AccelDeccelAmplitude : public ActionInterval{public: /** @brief Create the action with an inner action that has the amplitude property, and a duration time. @param action A pointer of the inner action. @param duration Specify the duration of the AccelDeccelAmplitude action. @return Return a pointer of AccelDeccelAmplitude action. When the creation failed, return nil. *//// 创建一个振幅动作 static AccelDeccelAmplitude* create(Action *action, float duration); /** @brief Get the value of amplitude rate. @return the value of amplitude rate. *//// 得到振幅的速率 inline float getRate(void) const { return _rate; } /** @brief Set the value of amplitude rate. @param rate Specify the value of amplitude rate. *//// 设置振幅的速率 inline void setRate(float rate) { _rate = rate; } // Overrides/// 继承自Action的方法 virtual void startWithTarget(Node *target) override; virtual void update(float time) override; virtual AccelDeccelAmplitude* clone() const override; virtual AccelDeccelAmplitude* reverse() const override; CC_CONSTRUCTOR_ACCESS: AccelDeccelAmplitude() {} virtual ~AccelDeccelAmplitude(); /** @brief Initializes the action with an inner action that has the amplitude property, and a duration time. @param action A pointer of the inner action. @param duration Specify the duration of the AccelDeccelAmplitude action. @return If the initialization success, return true; otherwise, return false. *//// 初始化 bool initWithAction(Action *action, float duration);protected: float _rate; ActionInterval *_other;private: CC_DISALLOW_COPY_AND_ASSIGN(AccelDeccelAmplitude);};/**@brief AccelAmplitude action.@js NA*//// 振幅动作class CC_DLL AccelAmplitude : public ActionInterval{public: /** @brief Create the action with an inner action that has the amplitude property, and a duration time. @param action A pointer of the inner action. @param duration Specify the duration of the AccelAmplitude action. @return Return a pointer of AccelAmplitude action. When the creation failed, return nil. */ /// 创建一个振幅动作 static AccelAmplitude* create(Action *action, float duration); /** @brief Get the value of amplitude rate. @return The value of amplitude rate. *//// 得到振幅的速率 inline float getRate() const { return _rate; } /** @brief Set the value of amplitude rate. @param rate Specify the value of amplitude rate. *//// 设置振幅的速率 inline void setRate(float rate) { _rate = rate; } // Overrides/// 继承自Action的方法 virtual void startWithTarget(Node *target) override; virtual void update(float time) override; virtual AccelAmplitude* clone() const override; virtual AccelAmplitude* reverse() const override; CC_CONSTRUCTOR_ACCESS: AccelAmplitude() {} virtual ~AccelAmplitude();/// 初始化 bool initWithAction(Action *action, float duration);protected: float _rate;/// 速率 ActionInterval *_other;/// 其他瞬时动作private: CC_DISALLOW_COPY_AND_ASSIGN(AccelAmplitude);};/**@brief DeccelAmplitude action.@js NA*/class CC_DLL DeccelAmplitude : public ActionInterval{public: /** @brief Creates the action with an inner action that has the amplitude property, and a duration time. @param action A pointer of the inner action. @param duration Specify the duration of the DeccelAmplitude action. @return Return a pointer of DeccelAmplitude. When the creation failed, return nil. *//// 创建这个动作需要一个有振幅属性的动作和间隔时间 static DeccelAmplitude* create(Action *action, float duration); /** @brief Get the value of amplitude rate. @return The value of amplitude rate. *//// 得到振幅的速率 inline float getRate() const { return _rate; } /** @brief Set the value of amplitude rate. @param rate Specify the value. *//// 设置振幅的速率 inline void setRate(float rate) { _rate = rate; } // overrides/// 继承自Action的方法 virtual void startWithTarget(Node *target) override; virtual void update(float time) override; virtual DeccelAmplitude* clone() const override; virtual DeccelAmplitude* reverse() const override; CC_CONSTRUCTOR_ACCESS: DeccelAmplitude() {} virtual ~DeccelAmplitude(); /** @brief Initializes the action with an inner action that has the amplitude property, and a duration time. @param action The pointer of inner action. @param duration The duration of the DeccelAmplitude action. @return If the initilization sucess, return true; otherwise, return false. *//// 初始化 bool initWithAction(Action *action, float duration);protected: float _rate; ActionInterval *_other;private: CC_DISALLOW_COPY_AND_ASSIGN(DeccelAmplitude);};/** @brief StopGrid action. @warning Don't call this action if another grid action is active. Call if you want to remove the the grid effect. Example: Sequence::actions(Lens::action(...), StopGrid::action(...), nullptr); */ /// 停止网格特效 /// 当另一个网格动作激活后,不要调用这个动作 /// 当你想移除一个网格特效的时候,按例子中调用: /// Sequence::actions(Lens::action(...), StopGrid::action(...), nullptr);class CC_DLL StopGrid : public ActionInstant{public: /** @brief Create a StopGrid Action. @return Return a pointer of StopGrid. When the creation failed, return nil. *//// 创建一个停止网格特效的动作 static StopGrid* create(); // Overrides/// 继承自Action的方法 virtual void startWithTarget(Node *target) override; virtual StopGrid* clone() const override; virtual StopGrid* reverse() const override;CC_CONSTRUCTOR_ACCESS: StopGrid() {} virtual ~StopGrid() {} protected: NodeGrid* _gridNodeTarget; /// 强制类型转换 void cacheTargetAsGridNode();private: CC_DISALLOW_COPY_AND_ASSIGN(StopGrid);};/** @brief ReuseGrid action.*//// 重用网格动作class CC_DLL ReuseGrid : public ActionInstant{public: /** @brief Create an action with the number of times that the current grid will be reused. @param times Specify times the grid will be reused. @return Return a pointer of ReuseGrid. When the creation failed, return nil. *//// 创建一个动作通过这个网格将被重用几次 static ReuseGrid* create(int times); // Override/// 继承自Action的方法 virtual void startWithTarget(Node *target) override; virtual ReuseGrid* clone() const override; virtual ReuseGrid* reverse() const override; CC_CONSTRUCTOR_ACCESS: ReuseGrid() {} virtual ~ReuseGrid() {} /** @brief Initializes an action with the number of times that the current grid will be reused. @param times Specify times the grid will be reused. @return If the initialization sucess, return true; otherwise, return false. *//// 初始化:/// 网格将被重用指定的次数 bool initWithTimes(int times);protected: NodeGrid* _gridNodeTarget; /// 强制类型转换 void cacheTargetAsGridNode(); int _times;private: CC_DISALLOW_COPY_AND_ASSIGN(ReuseGrid);};// end of actions group/// @}NS_CC_END#endif // __ACTION_CCGRID_ACTION_H__
0 0
- CCActionGird源码分析
- 源码分析
- 源码分析
- 源码分析
- 源码分析
- 源码分析
- 源码分析
- 源码分析
- 源码分析
- 源码分析:SparseArray分析
- 源码- Spark Broadcast源码分析
- Android源码/框架源码分析
- 【Android应用源码分析】HandlerThread 源码分析
- 【Android应用源码分析】IntentService 源码分析
- java源码分析01-Object源码分析
- VC++源码分析 - 中国象棋源码分析
- [Java源码分析]ArrayList源码分析
- [java源码分析]LinkedList源码分析
- 工业机器人动力学控制器设计概述
- 工厂模式和builder模式的区别
- IOS UI TabBar标签栏的使用
- 【zeroclipboard】复制到剪切板小功能
- Android开源项目
- CCActionGird源码分析
- Effective Objective-C 2.0学习笔记(部分)
- Delphi2010中DataSnap技术网摘
- 【玩转GridView】之隐藏域问题
- MSP430G2553与MSP430F5336系列单片机总结[3]——看门狗定时器
- 黑马程序员12交通信号灯系统
- 面向对象设计模拟简单ATM系统
- 基于Spring提供支持不同设备的页面
- (2.1.19.2)元数据