123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- //
- // ZGFrameActionSprite.cpp
- // Billiards
- //
- // Created by zhuge on 2018/9/6.
- //
- #include "ZGFrameActionSprite.h"
- #include "base/ccUTF8.h"
- #include "2d/CCSpriteFrameCache.h"
- USING_NS_CC;
- ZGFrameActionSprite* ZGFrameActionSprite::create() {
- ZGFrameActionSprite *ptr = new (std::nothrow) ZGFrameActionSprite();
- if(ptr != NULL && ptr->init()) {
- ptr->autorelease();
- return ptr;
- }
- CC_SAFE_DELETE(ptr);
- return NULL;
- }
- ZGFrameActionSprite::ZGFrameActionSprite()
- : _frameIndex (-1)
- {
-
- }
- ZGFrameActionSprite::~ZGFrameActionSprite(){
-
- }
- bool ZGFrameActionSprite::init() {
- Sprite::init();
- return true;
- }
- void ZGFrameActionSprite::setFrameNamePrefix(string prefix) {
- _frameNamePrefix = prefix;
- // updateFramePrefixAndIndex();
- }
- void ZGFrameActionSprite::setFrameIndex(int frameIndex) {
- _frameIndex = frameIndex;
- updateFramePrefixAndIndex();
- }
- void ZGFrameActionSprite::updateFramePrefixAndIndex() {
- auto name = StringUtils::format("%s%d.png", _frameNamePrefix.c_str(), _frameIndex);
- auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(name);
- if (!frame) {
- // 没有找到,如果
- CCLOG("ZGFrameActionSprite: updateFramePrefixAndIndex no frame named: %s", name.c_str());
- } else {
- setSpriteFrame(name);
- }
- }
|