01.
这一回主要搭建大致的框架,写程序的过程中错误不断,磕磕碰碰才写到现在,可见自己的能力是多么的差,所以要多写程序。
多思考代码的逻辑,
这一章主要谢了一个测试ActionManager,
其中有CallFunc和CallFuncN有什么区别?
CC_CALLBACK_0
CC_CALLBACK_1
和其它几个有什么区别?
回答这两个问题,写到这里进行下一章学习。
#ifndef ACTIONMANAGERLAYER_H
#define ACTIONMANAGERLAYER_H
#include "cocos2d.h"
USING_NS_CC;
static const char s_pathGrossini[] = "Images/grossini.png";
enum {
kTagNode,
kTagGrossini,
kTagSequence
};
class ActionManagerLayer : public Layer {
public:
ActionManagerLayer();
virtual ~ActionManagerLayer();
CREATE_FUNC(ActionManagerLayer);
virtual bool init();
static Scene *createScene();
private:
void removeThis();
};
#endif // ACTIONMANAGERLAYER_H
#include "ActionManagerLayer.h"
ActionManagerLayer::ActionManagerLayer()
{
}
ActionManagerLayer::~ActionManagerLayer()
{
}
bool ActionManagerLayer::init()
{
if (!Layer::init()) return false;
auto _screenSize = Director::getInstance()->getWinSize();
auto sprite = Sprite::create(s_pathGrossini);
sprite->setPosition(Vec2(_screenSize.width/2, _screenSize.height/2));
addChild(sprite, 1, kTagGrossini);
// Sum of all action's duration is 1.5 second.
//
sprite->runAction(RotateBy::create(1.5f, 90));
sprite->runAction(Sequence::create(DelayTime::create(1.4f),
FadeOut::create(1.1f), nullptr));
// After 1.5 second, self will be removed.
sprite->runAction(Sequence::create(DelayTime::create(1.4f),
CallFunc::create(CC_CALLBACK_0(ActionManagerLayer::removeThis, this)), nullptr));
return true;
}
cocos2d::Scene *ActionManagerLayer::createScene()
{
Scene *scene = Scene::create();
Layer *layer = ActionManagerLayer::create();
scene->addChild(layer);
return scene;
}
void ActionManagerLayer::removeThis()
{
auto sprite = getChildByTag(kTagGrossini);
sprite->removeChild(sprite, this);
}
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
#include "ActionManagerLayer.h"
USING_NS_CC;
Scene* HelloWorld::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer