Skip to content

Commit f8b694f

Browse files
author
Walzer
committed
issue cocos2d#161,update CCTMXLayer, CCTMXTiledMap, CCTextureCache
1 parent cf5dd95 commit f8b694f

File tree

3 files changed

+83
-58
lines changed

3 files changed

+83
-58
lines changed

cocos2dx/include/CCTMXLayer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace cocos2d {
3636
/** CCTMXLayer represents the TMX layer.
3737
3838
It is a subclass of CCSpriteSheet. By default the tiles are rendered using a CCTextureAtlas.
39-
If you mofify a tile on runtime, then, that tile will become a CCSprite.
39+
If you modify a tile on runtime, then, that tile will become a CCSprite, otherwise no CCSprite objects are created.
4040
The benefits of using CCSprite objects as tiles are:
4141
- tiles (CCSprite) can be rotated/scaled/moved with a nice API
4242

cocos2dx/include/CCTMXTiledMap.h

+52-50
Original file line numberDiff line numberDiff line change
@@ -47,56 +47,58 @@ namespace cocos2d {
4747
CCTMXOrientationIso,
4848
};
4949

50-
/** CCTMXTiledMap knows how to parse and render a TMX map.
51-
52-
It adds support for the TMX tiled map format used by http://www.mapeditor.org
53-
It supports isometric, hexagonal and orthogonal tiles.
54-
It also supports object groups, objects, and properties.
55-
56-
Features:
57-
- Each tile will be treated as an CCSprite
58-
- Each tile can be rotated / moved / scaled / tinted / "opacitied"
59-
- Tiles can be added/removed in runtime
60-
- The z-order of the tiles can be modified in runtime.
61-
- Each tile has an anchorPoint of (0,0)
62-
- The anchorPoint of the TMXTileMap is (0,0)
63-
- The TMX layers will be added as a child
64-
- The TMX layers will be aliased by default
65-
- The tileset image will be loaded using the TextureMgr
66-
- Each tile will have a unique tag
67-
- Each tile will have a unique z value. top-left: z=1, bottom-right: z=max z
68-
- Each object group will be treated as an NSMutableArray
69-
- Objects can be created using your own classes or a generic object class which will contain all the properties in a dictionary
70-
- Properties can be assigned to the Map, Layer, Object Group, and Object
71-
72-
Limitations:
73-
- It only supports one tileset per layer.
74-
- Embeded images are not supported
75-
- It only supports the XML format (the JSON format is not supported)
76-
77-
Technical description:
78-
Each layer is created using an TMXLayer (subclass of CCSpriteSheet). If you have 5 layers, then 5 TMXLayer will be created,
79-
unless the layer visibility is off. In that case, the layer won't be created at all.
80-
You can obtain the layers (TMXLayer objects) at runtime by:
81-
- [map getChildByTag: tag_number]; // 0=1st layer, 1=2nd layer, 2=3rd layer, etc...
82-
- [map layerNamed: name_of_the_layer];
83-
84-
Each object group is created using a TMXObjectGroup which is a subclass of NSMutableArray.
85-
You can obtain the object groups at runtime by:
86-
- [map objectGroupNamed: name_of_the_object_group];
87-
88-
Each object is a TMXObject.
89-
90-
Each property is stored as a key-value pair in an NSMutableDictionary.
91-
You can obtain the properties at runtime by:
92-
93-
[map propertyNamed: name_of_the_property];
94-
[layer propertyNamed: name_of_the_property];
95-
[objectGroup propertyNamed: name_of_the_property];
96-
[object propertyNamed: name_of_the_property];
97-
98-
@since v0.8.1
99-
*/
50+
/** CCTMXTiledMap knows how to parse and render a TMX map.
51+
52+
It adds support for the TMX tiled map format used by http://www.mapeditor.org
53+
It supports isometric, hexagonal and orthogonal tiles.
54+
It also supports object groups, objects, and properties.
55+
56+
Features:
57+
- Each tile will be treated as an CCSprite
58+
- The sprites are created on demand. They will be created only when you call "[layer tileAt:]"
59+
- Each tile can be rotated / moved / scaled / tinted / "opacitied", since each tile is a CCSprite
60+
- Tiles can be added/removed in runtime
61+
- The z-order of the tiles can be modified in runtime
62+
- Each tile has an anchorPoint of (0,0)
63+
- The anchorPoint of the TMXTileMap is (0,0)
64+
- The TMX layers will be added as a child
65+
- The TMX layers will be aliased by default
66+
- The tileset image will be loaded using the CCTextureCache
67+
- Each tile will have a unique tag
68+
- Each tile will have a unique z value. top-left: z=1, bottom-right: z=max z
69+
- Each object group will be treated as an NSMutableArray
70+
- Object class which will contain all the properties in a dictionary
71+
- Properties can be assigned to the Map, Layer, Object Group, and Object
72+
73+
Limitations:
74+
- It only supports one tileset per layer.
75+
- Embeded images are not supported
76+
- It only supports the XML format (the JSON format is not supported)
77+
78+
Technical description:
79+
Each layer is created using an CCTMXLayer (subclass of CCSpriteSheet). If you have 5 layers, then 5 CCTMXLayer will be created,
80+
unless the layer visibility is off. In that case, the layer won't be created at all.
81+
You can obtain the layers (CCTMXLayer objects) at runtime by:
82+
- [map getChildByTag: tag_number]; // 0=1st layer, 1=2nd layer, 2=3rd layer, etc...
83+
- [map layerNamed: name_of_the_layer];
84+
85+
Each object group is created using a CCTMXObjectGroup which is a subclass of NSMutableArray.
86+
You can obtain the object groups at runtime by:
87+
- [map objectGroupNamed: name_of_the_object_group];
88+
89+
Each object is a CCTMXObject.
90+
91+
Each property is stored as a key-value pair in an NSMutableDictionary.
92+
You can obtain the properties at runtime by:
93+
94+
[map propertyNamed: name_of_the_property];
95+
[layer propertyNamed: name_of_the_property];
96+
[objectGroup propertyNamed: name_of_the_property];
97+
[object propertyNamed: name_of_the_property];
98+
99+
@since v0.8.1
100+
*/
101+
100102
class CCX_DLL CCTMXTiledMap : public CCNode
101103
{
102104
/** the map's size property measured in tiles */

cocos2dx/textures/CCTextureCache.cpp

+30-7
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
178178
CCTexture2D * texture = NULL;
179179
// Split up directory and filename
180180
std::string fullpath(CCFileUtils::fullPathFromRelativePath(path));
181-
std::string temp(path);
182-
183181
// MUTEX:
184182
// Needed since addImageAsync calls this method from a different thread
185183

@@ -189,20 +187,44 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
189187

190188
if( ! texture )
191189
{
192-
// all images are handled by UIImage except PVR extension that is handled by our own handler
193-
// if ( [[path lowercaseString] hasSuffix:@".pvr"] )
194-
for (unsigned int i = 0; i < temp.length(); ++i)
190+
std::string lowerCase(path);
191+
for (unsigned int i = 0; i < lowerCase.length(); ++i)
195192
{
196-
temp[i] = tolower(temp[i]);
193+
lowerCase[i] = tolower(lowerCase[i]);
197194
}
198-
if (std::string::npos != temp.find(".pvr"))
195+
// all images are handled by UIImage except PVR extension that is handled by our own handler
196+
// if ( [[path lowercaseString] hasSuffix:@".pvr"] )
197+
198+
if (std::string::npos != lowerCase.find(".pvr"))
199199
{
200200
#ifdef _POWERVR_SUPPORT_
201201
texture = this->addPVRTCImage(fullpath.c_str());
202202
#endif
203203
}
204+
// Issue #886: TEMPORARY FIX FOR TRANSPARENT JPEGS IN IOS4
205+
// else if ( lowerCase.find(".jpg") || lowerCase(".jpeg") )
206+
// {
207+
// // convert jpg to png before loading the texture
208+
// UIImage *jpg = [[UIImage alloc] initWithContentsOfFile:fullpath];
209+
// UIImage *png = [[UIImage alloc] initWithData:UIImagePNGRepresentation(jpg)];
210+
// tex = [ [CCTexture2D alloc] initWithImage: png ];
211+
// [png release];
212+
// [jpg release];
213+
//
214+
// if( tex )
215+
// [textures setObject: tex forKey:path];
216+
// else
217+
// CCLOG(@"cocos2d: Couldn't add image:%@ in CCTextureCache", path);
218+
//
219+
// [tex release];
220+
// }
204221
else
205222
{
223+
//# work around for issue #910
224+
#if 0
225+
UIImage *image = [UIImage imageNamed:path];
226+
tex = [ [CCTexture2D alloc] initWithImage: image ];
227+
#else
206228
// prevents overloading the autorelease pool
207229
UIImage * image = new UIImage();
208230
if(! image->initWithContentsOfFile(fullpath))
@@ -213,6 +235,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
213235
texture = new CCTexture2D();
214236
texture->initWithImage(image);
215237
CCX_SAFE_DELETE(image);// image->release();
238+
#endif //
216239

217240
if( texture )
218241
{

0 commit comments

Comments
 (0)