cocos2dx v3精灵表动画

时间:2016-10-15 14:16:20

标签: c++ cocos2d-x-3.0

我是usimg cocos2dx v3。我正在尝试创建一个精灵表动画。但我收到此错误: void cocos2d::Vector<T>::pushBack(T) [with T = cocos2d::SpriteFrame*]: Assertion object != nullptr failed

这显然意味着我猜测我的矢量没有被初始化。但为什么会发生这种情况,我在Resources文件夹中有正确的文件名

auto cache = SpriteFrameCache::getInstance();
Vector<SpriteFrame*> frames = Vector<SpriteFrame*>();

frames.pushBack(cache->getSpriteFrameByName("1.png"));
frames.pushBack(cache->getSpriteFrameByName("2.png"));
frames.pushBack(cache->getSpriteFrameByName("3.png"));
frames.pushBack(cache->getSpriteFrameByName("4.png"));
frames.pushBack(cache->getSpriteFrameByName("5.png"));
frames.pushBack(cache->getSpriteFrameByName("6.png"));
Animation* anim = cocos2d::Animation::createWithSpriteFrames(frames, 0.1f, 1);

Animate* anim_action = cocos2d::Animate::create(anim);
auto sprite = Sprite::createWithSpriteFrame(frames.front());
sprite->runAction(RepeatForever::create(anim_action));
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(sprite, 0);

0 个答案:

没有答案
相关问题