CCParallaxNode.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2010-2012 cocos2d-x.org
  4. Copyright (c) 2011 Zynga Inc.
  5. Copyright (c) 2013-2016 Chukong Technologies Inc.
  6. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  7. http://www.cocos2d-x.org
  8. Permission is hereby granted, free of charge, to any person obtaining a copy
  9. of this software and associated documentation files (the "Software"), to deal
  10. in the Software without restriction, including without limitation the rights
  11. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. copies of the Software, and to permit persons to whom the Software is
  13. furnished to do so, subject to the following conditions:
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. THE SOFTWARE.
  23. ****************************************************************************/
  24. #ifndef __CCPARALLAX_NODE_H__
  25. #define __CCPARALLAX_NODE_H__
  26. #include "2d/CCNode.h"
  27. /*#include "ccArray.h"*/
  28. NS_CC_BEGIN
  29. struct _ccArray;
  30. /**
  31. * @addtogroup _2d
  32. * @{
  33. */
  34. /** @class ParallaxNode
  35. * @brief ParallaxNode: A node that simulates a parallax scroller
  36. The children will be moved faster / slower than the parent according the parallax ratio.
  37. */
  38. class CC_DLL ParallaxNode : public Node
  39. {
  40. public:
  41. /** Create a Parallax node.
  42. *
  43. * @return An autoreleased ParallaxNode object.
  44. */
  45. static ParallaxNode * create();
  46. // prevents compiler warning: "Included function hides overloaded virtual functions"
  47. using Node::addChild;
  48. /** Adds a child to the container with a local z-order, parallax ratio and position offset.
  49. *
  50. * @param child A child node.
  51. * @param z Z order for drawing priority.
  52. * @param parallaxRatio A given parallax ratio.
  53. * @param positionOffset A given position offset.
  54. */
  55. void addChild(Node * child, int z, const Vec2& parallaxRatio, const Vec2& positionOffset);
  56. /** Sets an array of layers for the Parallax node.
  57. *
  58. * @param parallaxArray An array of layers for the Parallax node.
  59. */
  60. void setParallaxArray( struct _ccArray *parallaxArray) { _parallaxArray = parallaxArray; }
  61. /** Returns the array of layers of the Parallax node.
  62. *
  63. * @return An array of layers for the Parallax node.
  64. */
  65. struct _ccArray* getParallaxArray() { return _parallaxArray; }
  66. const struct _ccArray* getParallaxArray() const { return _parallaxArray; }
  67. //
  68. // Overrides
  69. //
  70. virtual void addChild(Node * child, int zOrder, int tag) override;
  71. virtual void addChild(Node * child, int zOrder, const std::string &name) override;
  72. virtual void removeChild(Node* child, bool cleanup) override;
  73. virtual void removeAllChildrenWithCleanup(bool cleanup) override;
  74. virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
  75. CC_CONSTRUCTOR_ACCESS:
  76. /** Adds a child to the container with a z-order, a parallax ratio and a position offset
  77. It returns self, so you can chain several addChilds.
  78. @since v0.8
  79. * @js ctor
  80. */
  81. ParallaxNode();
  82. /**
  83. * @js NA
  84. * @lua NA
  85. */
  86. virtual ~ParallaxNode();
  87. protected:
  88. Vec2 absolutePosition();
  89. Vec2 _lastPosition;
  90. struct _ccArray* _parallaxArray;
  91. private:
  92. CC_DISALLOW_COPY_AND_ASSIGN(ParallaxNode);
  93. };
  94. // end of _2d group
  95. /// @}
  96. NS_CC_END
  97. #endif //__CCPARALLAX_NODE_H__