2010-12-27 10:26:56 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2010 Ricardo Quesada
|
2011-07-01 16:11:31 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2010-12-27 10:26:56 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CC_ANIMATION_CACHE_H__
|
|
|
|
#define __CC_ANIMATION_CACHE_H__
|
|
|
|
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "cocoa/CCObject.h"
|
|
|
|
#include "cocoa/CCDictionary.h"
|
2010-12-31 14:56:24 +08:00
|
|
|
|
|
|
|
#include <string>
|
2010-12-27 10:26:56 +08:00
|
|
|
|
2012-03-16 13:42:53 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class Animation;
|
2012-03-16 13:42:53 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup sprite_nodes
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2012-03-16 13:42:53 +08:00
|
|
|
/** Singleton that manages the Animations.
|
|
|
|
It saves in a cache the animations. You should use this class if you want to save your animations in a cache.
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Before v0.99.5, the recommend way was to save them on the Sprite. Since v0.99.5, you should use this class instead.
|
2012-03-16 13:42:53 +08:00
|
|
|
|
|
|
|
@since v0.99.5
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL AnimationCache : public Object
|
2010-12-27 10:26:56 +08:00
|
|
|
{
|
2012-03-16 13:42:53 +08:00
|
|
|
public:
|
2013-06-20 14:13:12 +08:00
|
|
|
AnimationCache();
|
|
|
|
~AnimationCache();
|
2012-09-17 15:02:24 +08:00
|
|
|
/** Returns the shared instance of the Animation cache */
|
2013-07-12 06:24:23 +08:00
|
|
|
static AnimationCache* getInstance();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** Purges the cache. It releases all the Animation objects and the shared instance.
|
2013-07-12 06:24:23 +08:00
|
|
|
*/
|
|
|
|
static void destroyInstance();
|
|
|
|
|
|
|
|
/** @deprecated Use getInstance() instead */
|
2013-07-18 07:56:19 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static AnimationCache* sharedAnimationCache() { return AnimationCache::getInstance(); }
|
2013-07-12 06:24:23 +08:00
|
|
|
|
|
|
|
/** @deprecatd Use destroyInstance() instead */
|
2013-07-18 07:56:19 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static void purgeSharedAnimationCache() { return AnimationCache::destroyInstance(); }
|
|
|
|
|
|
|
|
bool init(void);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** Adds a Animation with a name.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
void addAnimation(Animation *animation, const char * name);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** Deletes a Animation from the cache.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
|
|
|
void removeAnimationByName(const char* name);
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** Returns a Animation that was previously added.
|
2012-04-19 14:35:52 +08:00
|
|
|
If the name is not found it will return nil.
|
|
|
|
You should retain the returned copy if you are going to use it.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
Animation* animationByName(const char* name);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** Adds an animation from an NSDictionary
|
2013-06-20 14:13:12 +08:00
|
|
|
Make sure that the frames were previously loaded in the SpriteFrameCache.
|
2012-04-19 14:35:52 +08:00
|
|
|
@since v1.1
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
void addAnimationsWithDictionary(Dictionary* dictionary);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** Adds an animation from a plist file.
|
2013-06-20 14:13:12 +08:00
|
|
|
Make sure that the frames were previously loaded in the SpriteFrameCache.
|
2012-04-19 14:35:52 +08:00
|
|
|
@since v1.1
|
|
|
|
*/
|
|
|
|
void addAnimationsWithFile(const char* plist);
|
|
|
|
|
2012-03-16 13:42:53 +08:00
|
|
|
private:
|
2013-06-20 14:13:12 +08:00
|
|
|
void parseVersion1(Dictionary* animations);
|
|
|
|
void parseVersion2(Dictionary* animations);
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2012-03-16 13:42:53 +08:00
|
|
|
private:
|
2013-06-20 14:13:12 +08:00
|
|
|
Dictionary* _animations;
|
|
|
|
static AnimationCache* s_pSharedAnimationCache;
|
2012-03-16 13:42:53 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of sprite_nodes group
|
|
|
|
/// @}
|
|
|
|
|
2012-03-16 13:42:53 +08:00
|
|
|
NS_CC_END
|
2010-12-27 10:26:56 +08:00
|
|
|
|
|
|
|
#endif // __CC_ANIMATION_CACHE_H__
|