summary refs log tree commit diff stats
path: root/libs/cocos2d/CCTMXLayer.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/cocos2d/CCTMXLayer.h')
-rwxr-xr-xlibs/cocos2d/CCTMXLayer.h152
1 files changed, 152 insertions, 0 deletions
diff --git a/libs/cocos2d/CCTMXLayer.h b/libs/cocos2d/CCTMXLayer.h new file mode 100755 index 0000000..477a380 --- /dev/null +++ b/libs/cocos2d/CCTMXLayer.h
@@ -0,0 +1,152 @@
1/*
2 * cocos2d for iPhone: http://www.cocos2d-iphone.org
3 *
4 * Copyright (c) 2009-2010 Ricardo Quesada
5 * Copyright (c) 2011 Zynga Inc.
6 *
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 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 *
26 * TMX Tiled Map support:
27 * http://www.mapeditor.org
28 *
29 */
30
31
32#import "CCAtlasNode.h"
33#import "CCSpriteBatchNode.h"
34
35
36@class CCTMXMapInfo;
37@class CCTMXLayerInfo;
38@class CCTMXTilesetInfo;
39
40/** CCTMXLayer represents the TMX layer.
41
42 It is a subclass of CCSpriteBatchNode. By default the tiles are rendered using a CCTextureAtlas.
43 If you mofify a tile on runtime, then, that tile will become a CCSprite, otherwise no CCSprite objects are created.
44 The benefits of using CCSprite objects as tiles are:
45 - tiles (CCSprite) can be rotated/scaled/moved with a nice API
46
47 If the layer contains a property named "cc_vertexz" with an integer (in can be positive or negative),
48 then all the tiles belonging to the layer will use that value as their OpenGL vertex Z for depth.
49
50 On the other hand, if the "cc_vertexz" property has the "automatic" value, then the tiles will use an automatic vertex Z value.
51 Also before drawing the tiles, GL_ALPHA_TEST will be enabled, and disabled after drawing them. The used alpha func will be:
52
53 glAlphaFunc( GL_GREATER, value )
54
55 "value" by default is 0, but you can change it from Tiled by adding the "cc_alpha_func" property to the layer.
56 The value 0 should work for most cases, but if you have tiles that are semi-transparent, then you might want to use a differnt
57 value, like 0.5.
58
59 For further information, please see the programming guide:
60
61 http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps
62
63 @since v0.8.1
64 */
65@interface CCTMXLayer : CCSpriteBatchNode
66{
67 CCTMXTilesetInfo *tileset_;
68 NSString *layerName_;
69 CGSize layerSize_;
70 CGSize mapTileSize_;
71 uint32_t *tiles_; // GID are 32 bit
72 NSUInteger layerOrientation_;
73 NSMutableArray *properties_;
74
75 unsigned char opacity_; // TMX Layer supports opacity
76
77 NSUInteger minGID_;
78 NSUInteger maxGID_;
79
80 // Only used when vertexZ is used
81 NSInteger vertexZvalue_;
82 BOOL useAutomaticVertexZ_;
83 float alphaFuncValue_;
84
85 // used for optimization
86 CCSprite *reusedTile_;
87 ccCArray *atlasIndexArray_;
88}
89/** name of the layer */
90@property (nonatomic,readwrite,retain) NSString *layerName;
91/** size of the layer in tiles */
92@property (nonatomic,readwrite) CGSize layerSize;
93/** size of the map's tile (could be differnt from the tile's size) */
94@property (nonatomic,readwrite) CGSize mapTileSize;
95/** pointer to the map of tiles */
96@property (nonatomic,readwrite) uint32_t *tiles;
97/** Tilset information for the layer */
98@property (nonatomic,readwrite,retain) CCTMXTilesetInfo *tileset;
99/** Layer orientation, which is the same as the map orientation */
100@property (nonatomic,readwrite) NSUInteger layerOrientation;
101/** properties from the layer. They can be added using Tiled */
102@property (nonatomic,readwrite,retain) NSMutableArray *properties;
103
104/** creates a CCTMXLayer with an tileset info, a layer info and a map info */
105+(id) layerWithTilesetInfo:(CCTMXTilesetInfo*)tilesetInfo layerInfo:(CCTMXLayerInfo*)layerInfo mapInfo:(CCTMXMapInfo*)mapInfo;
106/** initializes a CCTMXLayer with a tileset info, a layer info and a map info */
107-(id) initWithTilesetInfo:(CCTMXTilesetInfo*)tilesetInfo layerInfo:(CCTMXLayerInfo*)layerInfo mapInfo:(CCTMXMapInfo*)mapInfo;
108
109/** dealloc the map that contains the tile position from memory.
110 Unless you want to know at runtime the tiles positions, you can safely call this method.
111 If you are going to call [layer tileGIDAt:] then, don't release the map
112 */
113-(void) releaseMap;
114
115/** returns the tile (CCSprite) at a given a tile coordinate.
116 The returned CCSprite will be already added to the CCTMXLayer. Don't add it again.
117 The CCSprite can be treated like any other CCSprite: rotated, scaled, translated, opacity, color, etc.
118 You can remove either by calling:
119 - [layer removeChild:sprite cleanup:cleanup];
120 - or [layer removeTileAt:ccp(x,y)];
121 */
122-(CCSprite*) tileAt:(CGPoint)tileCoordinate;
123
124/** returns the tile gid at a given tile coordinate.
125 if it returns 0, it means that the tile is empty.
126 This method requires the the tile map has not been previously released (eg. don't call [layer releaseMap])
127 */
128-(uint32_t) tileGIDAt:(CGPoint)tileCoordinate;
129
130/** sets the tile gid (gid = tile global id) at a given tile coordinate.
131 The Tile GID can be obtained by using the method "tileGIDAt" or by using the TMX editor -> Tileset Mgr +1.
132 If a tile is already placed at that position, then it will be removed.
133 */
134-(void) setTileGID:(uint32_t)gid at:(CGPoint)tileCoordinate;
135
136/** removes a tile at given tile coordinate */
137-(void) removeTileAt:(CGPoint)tileCoordinate;
138
139/** returns the position in pixels of a given tile coordinate */
140-(CGPoint) positionAt:(CGPoint)tileCoordinate;
141
142/** return the value for the specific property name */
143-(id) propertyNamed:(NSString *)propertyName;
144
145/** Creates the tiles */
146-(void) setupTiles;
147
148/** CCTMXLayer doesn't support adding a CCSprite manually.
149 @warning addchild:z:tag: is not supported on CCTMXLayer. Instead of setTileGID:at:/tileAt:
150 */
151-(void) addChild: (CCNode*)node z:(NSInteger)z tag:(NSInteger)tag;
152@end