Skip to content

Commit 5f7357b

Browse files
author
natural-law
committed
fixed #391,CCSpriteFrameCache support *.plist files with format value is not 0.
1 parent 1991a65 commit 5f7357b

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

cocos2dx/include/CCSpriteFrameCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class CC_DLL CCSpriteFrameCache : public CCObject
136136

137137
protected:
138138
CCDictionary<std::string, CCSpriteFrame*> *m_pSpriteFrames;
139-
CCDictionary<std::string, CCSpriteFrame*> *m_pSpriteFramesAliases;
139+
CCDictionary<std::string, CCString*> *m_pSpriteFramesAliases;
140140
};
141141
}//namespace cocos2d
142142

cocos2dx/platform/CCFileUtils.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ THE SOFTWARE.
2424

2525
#include "CCFileUtils.h"
2626

27-
#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS && CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
27+
#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
2828

2929
#include <stack>
3030
#include <libxml/parser.h>
@@ -55,12 +55,18 @@ class CCDictMaker : public CCSAXDelegator
5555
std::stack<CCDictionary<std::string, CCObject*>*> m_tDictStack;
5656
std::string m_sCurKey;///< parsed key
5757
CCSAXState m_tState;
58+
bool m_bInArray;
59+
CCMutableArray<CCObject*> *m_pArray;
60+
5861
public:
5962
CCDictMaker()
6063
{
6164
m_pRootDict = NULL;
6265
m_pCurDict = NULL;
6366
m_tState = SAX_NONE;
67+
68+
m_pArray = NULL;
69+
m_bInArray = false;
6470
}
6571
~CCDictMaker()
6672
{
@@ -119,6 +125,11 @@ class CCDictMaker : public CCSAXDelegator
119125
}
120126
else
121127
{
128+
if (sName == "array")
129+
{
130+
m_bInArray = true;
131+
m_pArray = new CCMutableArray<CCObject*>();
132+
}
122133
m_tState = SAX_NONE;
123134
}
124135
}
@@ -134,6 +145,14 @@ class CCDictMaker : public CCSAXDelegator
134145
m_pCurDict = (CCDictionary<std::string, CCObject*>*)(m_tDictStack.top());
135146
}
136147
}
148+
else if (sName == "array")
149+
{
150+
CCAssert(m_bInArray, "The plist file is wrong!");
151+
m_pCurDict->setObject(m_pArray, m_sCurKey);
152+
m_pArray->release();
153+
m_pArray = NULL;
154+
m_bInArray = false;
155+
}
137156
m_tState = SAX_NONE;
138157
}
139158

@@ -156,7 +175,15 @@ class CCDictMaker : public CCSAXDelegator
156175
case SAX_STRING:
157176
{
158177
CCAssert(!m_sCurKey.empty(), "not found key : <integet/real>");
159-
m_pCurDict->setObject(pText, m_sCurKey);
178+
179+
if (m_bInArray)
180+
{
181+
m_pArray->addObject(pText);
182+
}
183+
else
184+
{
185+
m_pCurDict->setObject(pText, m_sCurKey);
186+
}
160187
break;
161188
}
162189
}

cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void CCSpriteFrameCache::purgeSharedSpriteFrameCache(void)
5858
bool CCSpriteFrameCache::init(void)
5959
{
6060
m_pSpriteFrames= new CCDictionary<std::string, CCSpriteFrame*>();
61-
m_pSpriteFramesAliases = new CCDictionary<std::string, CCSpriteFrame*>();
61+
m_pSpriteFramesAliases = new CCDictionary<std::string, CCString*>();
6262
return true;
6363
}
6464

@@ -155,10 +155,6 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
155155
} else
156156
if (format == 3)
157157
{
158-
/// @todo what's the format look like?
159-
assert(false);
160-
return;
161-
/*
162158
// get values
163159
CCSize spriteSize = CCSizeFromString(valueForKey("spriteSize", frameDict));
164160
CCPoint spriteOffset = CCPointFromString(valueForKey("spriteOffset", frameDict));
@@ -167,19 +163,28 @@ void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string,
167163
bool textureRotated = atoi(valueForKey("textureRotated", frameDict)) == 0;
168164

169165
// get aliases
170-
CCMutableArray<CCString*> *aliases = CCMutableArray<CCString*>dictionary->objectForKey(std::string("aliases"));
171-
172-
while( alias = (CCDictionary<std::string, CCObject*>*)aliases->next(&key) )
173-
{
174-
std::string value = ((CCString*)alias->objectForKey(key))->m_sString();
175-
if (m_pSpriteFramesAliases->objectForKey(value))
176-
{
177-
CCLOG("cocos2d: WARNING: an alias with name %s already exists", value.c_str());
178-
}
179-
180-
m_pSpriteFramesAliases->setObject(frameDict, value);
181-
}
182-
*/
166+
CCMutableArray<CCString*> *aliases = (CCMutableArray<CCString*> *) (frameDict->objectForKey(std::string("aliases")));
167+
CCMutableArray<CCString*>::CCMutableArrayIterator iter;
168+
169+
CCString * frameKey = new CCString(key.c_str());
170+
for (iter = aliases->begin(); iter != aliases->end(); iter++)
171+
{
172+
std::string oneAlias = ((CCString*) (*iter))->m_sString;
173+
if (m_pSpriteFramesAliases->objectForKey(oneAlias))
174+
{
175+
CCLOG("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
176+
}
177+
178+
m_pSpriteFramesAliases->setObject(frameKey, oneAlias);
179+
}
180+
frameKey->release();
181+
// create frame
182+
spriteFrame = new CCSpriteFrame();
183+
spriteFrame->initWithTexture(pobTexture,
184+
CCRectMake(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
185+
textureRotated,
186+
spriteOffset,
187+
spriteSourceSize);
183188
}
184189

185190
// add sprite frame
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1df0bf26583b2b3cfde43364d98d925393dddb51
1+
9e16647d99e1705b6436f4764cfacc6a478d3715

0 commit comments

Comments
 (0)