2010-12-27 10:26:56 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-07-01 16:11:31 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2016-04-08 13:40:36 +08:00
|
|
|
CopyRight (c) 2013-2016 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__
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCRef.h"
|
2014-04-27 01:35:57 +08:00
|
|
|
#include "base/CCMap.h"
|
|
|
|
#include "base/CCValue.h"
|
2014-07-11 10:19:49 +08:00
|
|
|
#include "2d/CCAnimation.h"
|
2014-02-20 10:53:49 +08:00
|
|
|
|
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
|
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
|
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
|
|
|
/**
|
2015-03-21 17:06:26 +08:00
|
|
|
* @addtogroup _2d
|
2012-06-20 18:09:11 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
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
|
2015-03-18 21:45:58 +08:00
|
|
|
@js cc.animationCache
|
2012-03-16 13:42:53 +08:00
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
class CC_DLL AnimationCache : public Ref
|
2010-12-27 10:26:56 +08:00
|
|
|
{
|
2012-03-16 13:42:53 +08:00
|
|
|
public:
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
AnimationCache();
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
~AnimationCache();
|
2015-03-18 21:45:58 +08:00
|
|
|
/** Returns the shared instance of the Animation cache
|
|
|
|
@js NA
|
|
|
|
*/
|
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.
|
2015-03-18 21:45:58 +08:00
|
|
|
@js NA
|
2013-07-12 06:24:23 +08:00
|
|
|
*/
|
|
|
|
static void destroyInstance();
|
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** @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
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** @deprecated 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.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @param animation An animation.
|
|
|
|
* @param name The name of animation.
|
|
|
|
*/
|
2013-11-06 11:02:03 +08:00
|
|
|
void addAnimation(Animation *animation, const std::string& name);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** Deletes a Animation from the cache.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @param name The name of animation.
|
2013-09-13 11:41:20 +08:00
|
|
|
*/
|
2013-11-06 11:02:03 +08:00
|
|
|
void removeAnimation(const std::string& name);
|
2013-09-13 11:41:20 +08:00
|
|
|
/** @deprecated. Use removeAnimation() instead
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-11-06 11:02:03 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void removeAnimationByName(const std::string& name){ removeAnimation(name);}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** Returns a Animation that was previously added.
|
2015-03-18 20:05:59 +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.
|
|
|
|
*
|
|
|
|
* @return A Animation that was previously added. If the name is not found it will return nil.
|
|
|
|
*/
|
2013-11-06 11:02:03 +08:00
|
|
|
Animation* getAnimation(const std::string& name);
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-18 20:05:59 +08:00
|
|
|
* @deprecated. Use getAnimation() instead
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-11-06 11:02:03 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Animation* animationByName(const std::string& name){ return getAnimation(name); }
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Adds an animation from an NSDictionary.
|
|
|
|
* Make sure that the frames were previously loaded in the SpriteFrameCache.
|
2015-03-18 20:26:16 +08:00
|
|
|
* @param dictionary An NSDictionary.
|
2015-03-18 20:05:59 +08:00
|
|
|
* @param plist The path of the relative file,it use to find the plist path for load SpriteFrames.
|
|
|
|
* @since v1.1
|
2015-03-18 21:45:58 +08:00
|
|
|
@js NA
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2014-01-06 20:23:45 +08:00
|
|
|
void addAnimationsWithDictionary(const ValueMap& dictionary,const std::string& plist);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** Adds an animation from a plist file.
|
2015-03-18 20:05:59 +08:00
|
|
|
* Make sure that the frames were previously loaded in the SpriteFrameCache.
|
|
|
|
* @since v1.1
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js addAnimations
|
|
|
|
* @lua addAnimations
|
2015-03-18 20:26:16 +08:00
|
|
|
* @param plist An animation from a plist file.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2013-11-06 11:02:03 +08:00
|
|
|
void addAnimationsWithFile(const std::string& plist);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-03-16 13:42:53 +08:00
|
|
|
private:
|
2013-12-04 17:46:57 +08:00
|
|
|
void parseVersion1(const ValueMap& animations);
|
|
|
|
void parseVersion2(const ValueMap& animations);
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2012-03-16 13:42:53 +08:00
|
|
|
private:
|
2013-12-03 14:47:35 +08:00
|
|
|
Map<std::string, Animation*> _animations;
|
2013-12-18 17:47:20 +08:00
|
|
|
static AnimationCache* s_sharedAnimationCache;
|
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
|
|
|
|
2013-08-01 17:09:23 +08:00
|
|
|
#endif // __CC_ANIMATION_CACHE_H__
|