cocos2d-x cpp-test学习

本文记录了使用cocos2d-x进行cpp-test项目框架搭建的过程,期间遇到了诸多问题并逐一解决。重点探讨了ActionManager中CallFunc和CallFuncN的区别,以及CC_CALLBACK_0、CC_CALLBACK_1等宏的用法,旨在深化对cocos2d-x编程的理解。后续将继续深入学习。
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值