CCActionProgressTimer.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /****************************************************************************
  2. Copyright (C) 2010 Lam Pham
  3. Copyright (c) 2010-2012 cocos2d-x.org
  4. Copyright (c) 2013-2016 Chukong Technologies Inc.
  5. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  6. http://www.cocos2d-x.org
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. ****************************************************************************/
  23. #ifndef __ACTION_CCPROGRESS_TIMER_H__
  24. #define __ACTION_CCPROGRESS_TIMER_H__
  25. #include "2d/CCActionInterval.h"
  26. NS_CC_BEGIN
  27. /**
  28. * @addtogroup actions
  29. * @{
  30. */
  31. /**
  32. @brief Progress to percentage.
  33. @details This action show the target node from current percentage to the specified percentage.
  34. You should specify the destination percentage when creating the action.
  35. @since v0.99.1
  36. */
  37. class CC_DLL ProgressTo : public ActionInterval
  38. {
  39. public:
  40. /**
  41. * @brief Create and initializes with a duration and a destination percentage.
  42. * @param duration Specify the duration of the ProgressTo action. It's a value in seconds.
  43. * @param percent Specify the destination percentage.
  44. * @return If the creation success, return a pointer of ProgressTo action; otherwise, return nil.
  45. */
  46. static ProgressTo* create(float duration, float percent);
  47. //
  48. // Overrides
  49. //
  50. virtual ProgressTo* clone() const override;
  51. virtual ProgressTo* reverse() const override;
  52. virtual void startWithTarget(Node *target) override;
  53. virtual void update(float time) override;
  54. CC_CONSTRUCTOR_ACCESS:
  55. ProgressTo() {}
  56. virtual ~ProgressTo() {}
  57. /**
  58. * @brief Initializes with a duration and destination percentage.
  59. * @param duration Specify the duration of the ProgressTo action. It's a value in seconds.
  60. * @param percent Specify the destination percentage.
  61. * @return If the creation success, return true; otherwise, return false.
  62. */
  63. bool initWithDuration(float duration, float percent);
  64. protected:
  65. float _to;
  66. float _from;
  67. private:
  68. CC_DISALLOW_COPY_AND_ASSIGN(ProgressTo);
  69. };
  70. /**
  71. @brief Progress from a percentage to another percentage.
  72. @since v0.99.1
  73. */
  74. class CC_DLL ProgressFromTo : public ActionInterval
  75. {
  76. public:
  77. /**
  78. * @brief Create and initializes the action with a duration, a "from" percentage and a "to" percentage.
  79. * @param duration Specify the duration of the ProgressFromTo action. It's a value in seconds.
  80. * @param fromPercentage Specify the source percentage.
  81. * @param toPercentage Specify the destination percentage.
  82. * @return If the creation success, return a pointer of ProgressFromTo action; otherwise, return nil.
  83. */
  84. static ProgressFromTo* create(float duration, float fromPercentage, float toPercentage);
  85. //
  86. // Overrides
  87. //
  88. virtual ProgressFromTo* clone() const override;
  89. virtual ProgressFromTo* reverse() const override;
  90. virtual void startWithTarget(Node *target) override;
  91. virtual void update(float time) override;
  92. CC_CONSTRUCTOR_ACCESS:
  93. ProgressFromTo() {}
  94. virtual ~ProgressFromTo() {}
  95. /**
  96. * @brief Initializes the action with a duration, a "from" percentage and a "to" percentage.
  97. * @param duration Specify the duration of the ProgressFromTo action. It's a value in seconds.
  98. * @param fromPercentage Specify the source percentage.
  99. * @param toPercentage Specify the destination percentage.
  100. * @return If the creation success, return true; otherwise, return false.
  101. */
  102. bool initWithDuration(float duration, float fromPercentage, float toPercentage);
  103. protected:
  104. float _to;
  105. float _from;
  106. private:
  107. CC_DISALLOW_COPY_AND_ASSIGN(ProgressFromTo);
  108. };
  109. // end of actions group
  110. /// @}
  111. NS_CC_END
  112. #endif // __ACTION_CCPROGRESS_TIMER_H__