/trunk/MTSTGGameEditor/MTSTGGameEditor/libs/cocos2d/CCSpriteBatchNode.h

http://mz-stg-game.googlecode.com/ · C Header · 125 lines · 31 code · 20 blank · 74 comment · 0 complexity · 865607da85d6f9ab917f1b19a8be827f MD5 · raw file

  1. /*
  2. * cocos2d for iPhone: http://www.cocos2d-iphone.org
  3. *
  4. * Copyright (C) 2009 Matt Oswald
  5. *
  6. * Copyright (c) 2009-2010 Ricardo Quesada
  7. * Copyright (c) 2011 Zynga Inc.
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #import "CCNode.h"
  29. #import "CCProtocols.h"
  30. #import "CCTextureAtlas.h"
  31. #import "ccMacros.h"
  32. #pragma mark CCSpriteBatchNode
  33. @class CCSprite;
  34. /** CCSpriteBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call
  35. * (often known as "batch draw").
  36. *
  37. * A CCSpriteBatchNode can reference one and only one texture (one image file, one texture atlas).
  38. * Only the CCSprites that are contained in that texture can be added to the CCSpriteBatchNode.
  39. * All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call.
  40. * If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient.
  41. *
  42. *
  43. * Limitations:
  44. * - The only object that is accepted as child (or grandchild, grand-grandchild, etc...) is CCSprite or any subclass of CCSprite. eg: particles, labels and layer can't be added to a CCSpriteBatchNode.
  45. * - Either all its children are Aliased or Antialiased. It can't be a mix. This is because "alias" is a property of the texture, and all the sprites share the same texture.
  46. *
  47. * @since v0.7.1
  48. */
  49. @interface CCSpriteBatchNode : CCNode <CCTextureProtocol>
  50. {
  51. CCTextureAtlas *textureAtlas_;
  52. ccBlendFunc blendFunc_;
  53. // all descendants: chlidren, gran children, etc...
  54. CCArray *descendants_;
  55. }
  56. /** returns the TextureAtlas that is used */
  57. @property (nonatomic,readwrite,retain) CCTextureAtlas * textureAtlas;
  58. /** conforms to CCTextureProtocol protocol */
  59. @property (nonatomic,readwrite) ccBlendFunc blendFunc;
  60. /** descendants (children, gran children, etc) */
  61. @property (nonatomic,readonly) CCArray *descendants;
  62. /** creates a CCSpriteBatchNode with a texture2d and a default capacity of 29 children.
  63. The capacity will be increased in 33% in runtime if it run out of space.
  64. */
  65. +(id)batchNodeWithTexture:(CCTexture2D *)tex;
  66. /** creates a CCSpriteBatchNode with a texture2d and capacity of children.
  67. The capacity will be increased in 33% in runtime if it run out of space.
  68. */
  69. +(id)batchNodeWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity;
  70. /** creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) with a default capacity of 29 children.
  71. The capacity will be increased in 33% in runtime if it run out of space.
  72. The file will be loaded using the TextureMgr.
  73. */
  74. +(id)batchNodeWithFile:(NSString*) fileImage;
  75. /** creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and capacity of children.
  76. The capacity will be increased in 33% in runtime if it run out of space.
  77. The file will be loaded using the TextureMgr.
  78. */
  79. +(id)batchNodeWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity;
  80. /** initializes a CCSpriteBatchNode with a texture2d and capacity of children.
  81. The capacity will be increased in 33% in runtime if it run out of space.
  82. */
  83. -(id)initWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity;
  84. /** initializes a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children.
  85. The capacity will be increased in 33% in runtime if it run out of space.
  86. The file will be loaded using the TextureMgr.
  87. */
  88. -(id)initWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity;
  89. -(void) increaseAtlasCapacity;
  90. /** removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter.
  91. @warning Removing a child from a CCSpriteBatchNode is very slow
  92. */
  93. -(void)removeChildAtIndex:(NSUInteger)index cleanup:(BOOL)doCleanup;
  94. /** removes a child given a reference. It will also cleanup the running actions depending on the cleanup parameter.
  95. @warning Removing a child from a CCSpriteBatchNode is very slow
  96. */
  97. -(void)removeChild: (CCSprite *)sprite cleanup:(BOOL)doCleanup;
  98. -(void) insertChild:(CCSprite*)child inAtlasAtIndex:(NSUInteger)index;
  99. -(void) appendChild:(CCSprite*)sprite;
  100. -(void) removeSpriteFromAtlas:(CCSprite*)sprite;
  101. -(NSUInteger) rebuildIndexInOrder:(CCSprite*)parent atlasIndex:(NSUInteger)index;
  102. -(NSUInteger) atlasIndexForChild:(CCSprite*)sprite atZ:(NSInteger)z;
  103. /* Sprites use this to start sortChildren, don't call this manually */
  104. - (void) reorderBatch:(BOOL) reorder;
  105. @end