为什么在按钮回调里runAction之前的动画一直报错?

C艾斯蒂嗯蟹 2018-11-07 12:09:35
自己定义的类 ↓↓↓
.h
#pragma once
#include "cocos2d.h"

class MyCososAnimate :public cocos2d::Node
{
public:
MyCososAnimate();
~MyCososAnimate();

cocos2d::Sprite* m_sprite = nullptr;
cocos2d::Animation* m_animation = nullptr;
cocos2d::Animate* m_animate = nullptr;
cocos2d::ActionInterval * m_action = nullptr;

bool MyRunAction();
virtual bool init(cocos2d::Scene*);
static MyCososAnimate* create(cocos2d::Scene*);
};


.cpp
#include "MyCososAnimate.h"
using namespace cocos2d;
MyCososAnimate::MyCososAnimate()
{
}


MyCososAnimate::~MyCososAnimate()
{
}

MyCososAnimate* MyCososAnimate::create(cocos2d::Scene* _pScene){
MyCososAnimate* pRet = new MyCososAnimate();
if (pRet && pRet->init(_pScene))
{
pRet->autorelease();
}
else
{
delete pRet;
pRet = nullptr;
}
return pRet;
}

bool MyCososAnimate::init(cocos2d::Scene* _pScene){
auto visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
// add "HelloWorld" splash screen"
m_sprite = Sprite::create("images/Down_01.png");
Vector<SpriteFrame*> animFrames;
int tmpSize = 4;
animFrames.reserve(4);
for (int i = 1; i <= tmpSize; i++)
{
char tmpStr[50] = {};
sprintf_s(tmpStr, "images/Down_0%d.png", i);
animFrames.pushBack(SpriteFrame::create(tmpStr, Rect(0, 0, 25, 41)));
}
//Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
//Animate* animate = Animate::create(animation);
m_animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
m_animate = Animate::create(m_animation);
m_animate->retain();
m_sprite->setScale(2.0f);
// run it and repeat it forever
m_action = CCRepeatForever::create(m_animate);
// position the sprite on the center of the screen
m_sprite->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));

// add the sprite as a child to this layer
_pScene->addChild(m_sprite, 0);

return true;
}

bool MyCososAnimate::MyRunAction(){
m_sprite->runAction(m_action);
return true;
}


HELLOWORLD里点击右下角按钮播放动画
void HelloWorld::menuCloseCallback(Ref* pSender)
{
tmpAni->MyRunAction();
}


到RUNACTION就报错了。。。

...全文
103 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
m_action = CCRepeatForever::create(m_animate); //动画好像不是这么创建的吧?我记得好像是有一个Animation
C艾斯蒂嗯蟹 2018-11-07
  • 打赏
  • 举报
回复
DIRECTOR::GETINSTANCE()->getActionManager()->PauseTarget(node) 好像可以解决暂停,继续的问题

721

社区成员

发帖
与我相关
我的任务
社区描述
Cocos2d-x相关内容讨论专区
社区管理员
  • Cocos2d-x
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧