summary refs log tree commit diff stats
path: root/libs/cocos2d/CCSpriteBatchNode.h
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
committerStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
commit9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch)
tree5bac45ae5157a1cb10c6e45500cbf72789917980 /libs/cocos2d/CCSpriteBatchNode.h
downloadcartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip
Initial commit (version 0.2.1)
Diffstat (limited to 'libs/cocos2d/CCSpriteBatchNode.h')
-rwxr-xr-xlibs/cocos2d/CCSpriteBatchNode.h145
1 files changed, 145 insertions, 0 deletions
diff --git a/libs/cocos2d/CCSpriteBatchNode.h b/libs/cocos2d/CCSpriteBatchNode.h new file mode 100755 index 0000000..0342e24 --- /dev/null +++ b/libs/cocos2d/CCSpriteBatchNode.h
@@ -0,0 +1,145 @@
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
29
30#import "CCNode.h"
31#import "CCProtocols.h"
32#import "CCTextureAtlas.h"
33#import "ccMacros.h"
34
35#pragma mark CCSpriteBatchNode
36
37@class CCSprite;
38
39/** CCSpriteBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call
40 * (often known as "batch draw").
41 *
42 * A CCSpriteBatchNode can reference one and only one texture (one image file, one texture atlas).
43 * Only the CCSprites that are contained in that texture can be added to the CCSpriteBatchNode.
44 * All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call.
45 * 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.
46 *
47 *
48 * Limitations:
49 * - 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.
50 * - 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.
51 *
52 * @since v0.7.1
53 */
54@interface CCSpriteBatchNode : CCNode <CCTextureProtocol>
55{
56 CCTextureAtlas *textureAtlas_;
57 ccBlendFunc blendFunc_;
58
59 // all descendants: chlidren, gran children, etc...
60 CCArray *descendants_;
61}
62
63/** returns the TextureAtlas that is used */
64@property (nonatomic,readwrite,retain) CCTextureAtlas * textureAtlas;
65
66/** conforms to CCTextureProtocol protocol */
67@property (nonatomic,readwrite) ccBlendFunc blendFunc;
68
69/** descendants (children, gran children, etc) */
70@property (nonatomic,readonly) CCArray *descendants;
71
72/** creates a CCSpriteBatchNode with a texture2d and a default capacity of 29 children.
73 The capacity will be increased in 33% in runtime if it run out of space.
74 */
75+(id)batchNodeWithTexture:(CCTexture2D *)tex;
76+(id)spriteSheetWithTexture:(CCTexture2D *)tex DEPRECATED_ATTRIBUTE;
77
78/** creates a CCSpriteBatchNode with a texture2d and capacity of children.
79 The capacity will be increased in 33% in runtime if it run out of space.
80 */
81+(id)batchNodeWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity;
82+(id)spriteSheetWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity DEPRECATED_ATTRIBUTE;
83
84/** creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) with a default capacity of 29 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)batchNodeWithFile:(NSString*) fileImage;
89+(id)spriteSheetWithFile:(NSString*) fileImage DEPRECATED_ATTRIBUTE;
90
91/** creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and capacity of children.
92 The capacity will be increased in 33% in runtime if it run out of space.
93 The file will be loaded using the TextureMgr.
94*/
95+(id)batchNodeWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity;
96+(id)spriteSheetWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity DEPRECATED_ATTRIBUTE;
97
98/** initializes a CCSpriteBatchNode with a texture2d and capacity of children.
99 The capacity will be increased in 33% in runtime if it run out of space.
100 */
101-(id)initWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity;
102/** initializes a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children.
103 The capacity will be increased in 33% in runtime if it run out of space.
104 The file will be loaded using the TextureMgr.
105 */
106-(id)initWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity;
107
108-(void) increaseAtlasCapacity;
109
110/** creates an sprite with a rect in the CCSpriteBatchNode.
111 It's the same as:
112 - create an standard CCSsprite
113 - set the usingSpriteSheet = YES
114 - set the textureAtlas to the same texture Atlas as the CCSpriteBatchNode
115 @deprecated Use [CCSprite spriteWithBatchNode:rect:] instead;
116 */
117-(CCSprite*) createSpriteWithRect:(CGRect)rect DEPRECATED_ATTRIBUTE;
118
119/** initializes a previously created sprite with a rect. This sprite will have the same texture as the CCSpriteBatchNode.
120 It's the same as:
121 - initialize an standard CCSsprite
122 - set the usingBatchNode = YES
123 - set the textureAtlas to the same texture Atlas as the CCSpriteBatchNode
124 @since v0.99.0
125 @deprecated Use [CCSprite initWithBatchNode:rect:] instead;
126*/
127-(void) initSprite:(CCSprite*)sprite rect:(CGRect)rect DEPRECATED_ATTRIBUTE;
128
129/** removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter.
130 @warning Removing a child from a CCSpriteBatchNode is very slow
131 */
132-(void)removeChildAtIndex:(NSUInteger)index cleanup:(BOOL)doCleanup;
133
134/** removes a child given a reference. It will also cleanup the running actions depending on the cleanup parameter.
135 @warning Removing a child from a CCSpriteBatchNode is very slow
136 */
137-(void)removeChild: (CCSprite *)sprite cleanup:(BOOL)doCleanup;
138
139-(void) insertChild:(CCSprite*)child inAtlasAtIndex:(NSUInteger)index;
140-(void) removeSpriteFromAtlas:(CCSprite*)sprite;
141
142-(NSUInteger) rebuildIndexInOrder:(CCSprite*)parent atlasIndex:(NSUInteger)index;
143-(NSUInteger) atlasIndexForChild:(CCSprite*)sprite atZ:(NSInteger)z;
144
145@end