axmol/cocos/2d/CCAnimationCache.h

150 lines
4.7 KiB
C
Raw Normal View History

2010-12-27 10:26:56 +08:00
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2017 Chukong Technologies 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__
#include "base/CCRef.h"
2014-04-27 01:35:57 +08:00
#include "base/CCMap.h"
#include "base/CCValue.h"
#include "2d/CCAnimation.h"
#include <string>
2010-12-27 10:26:56 +08:00
NS_CC_BEGIN
class Animation;
2012-06-20 18:09:11 +08:00
/**
2015-03-21 17:06:26 +08:00
* @addtogroup _2d
2012-06-20 18:09:11 +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.
Before v0.99.5, the recommend way was to save them on the Sprite. Since v0.99.5, you should use this class instead.
@since v0.99.5
@js cc.animationCache
*/
class CC_DLL AnimationCache : public Ref
2010-12-27 10:26:56 +08:00
{
public:
/**
* @js ctor
*/
AnimationCache();
/**
* @js NA
* @lua NA
*/
~AnimationCache();
/** Returns the shared instance of the Animation cache
@js NA
*/
static AnimationCache* getInstance();
/** Purges the cache. It releases all the Animation objects and the shared instance.
@js NA
*/
static void destroyInstance();
/** @deprecated Use getInstance() instead. */
CC_DEPRECATED_ATTRIBUTE static AnimationCache* sharedAnimationCache() { return AnimationCache::getInstance(); }
/** @deprecated Use destroyInstance() instead. */
CC_DEPRECATED_ATTRIBUTE static void purgeSharedAnimationCache() { return AnimationCache::destroyInstance(); }
bool init(void);
/** Adds a Animation with a name.
*
* @param animation An animation.
* @param name The name of animation.
*/
void addAnimation(Animation *animation, const std::string& name);
/** Deletes a Animation from the cache.
*
* @param name The name of animation.
*/
void removeAnimation(const std::string& name);
/** @deprecated. Use removeAnimation() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE void removeAnimationByName(const std::string& name){ removeAnimation(name);}
/** Returns a Animation that was previously added.
* If the name is not found it will return nil.
* You should retain the returned copy if you are going to use it.
*
* @return A Animation that was previously added. If the name is not found it will return nil.
*/
Animation* getAnimation(const std::string& name);
/**
* @deprecated. Use getAnimation() instead
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE Animation* animationByName(const std::string& name){ return getAnimation(name); }
/** Adds an animation from an NSDictionary.
* Make sure that the frames were previously loaded in the SpriteFrameCache.
* @param dictionary An NSDictionary.
* @param plist The path of the relative file,it use to find the plist path for load SpriteFrames.
* @since v1.1
@js NA
*/
void addAnimationsWithDictionary(const ValueMap& dictionary,const std::string& plist);
/** Adds an animation from a plist file.
* Make sure that the frames were previously loaded in the SpriteFrameCache.
* @since v1.1
* @js addAnimations
* @lua addAnimations
* @param plist An animation from a plist file.
*/
void addAnimationsWithFile(const std::string& plist);
private:
void parseVersion1(const ValueMap& animations);
void parseVersion2(const ValueMap& animations);
private:
Map<std::string, Animation*> _animations;
static AnimationCache* s_sharedAnimationCache;
};
2012-06-20 18:09:11 +08:00
// end of sprite_nodes group
/// @}
NS_CC_END
2010-12-27 10:26:56 +08:00
#endif // __CC_ANIMATION_CACHE_H__