zoukankan      html  css  js  c++  java
  • cocos2d-x图层以及显示对象的基本使用

    LogoNode:

    #ifndef LogoNode_hpp

    #define LogoNode_hpp

    #include <stdio.h>

    #include "cocos2d.h"

    USING_NS_CC;

    class LogoNode:public Node

    {

    protected:

        Sprite* _logo;

        Sprite* _cocosLogo;

        

    public:

        LogoNode();

        virtual ~LogoNode();

        

        virtual bool init();

        

        CREATE_FUNC(LogoNode);

    };

    #endif /* LogoNode_hpp */

    #include "LogoNode.hpp"

    LogoNode::LogoNode():_logo(nullptr),_cocosLogo(nullptr)

    {

        

    }

    LogoNode::~LogoNode()

    {

        

    }

    bool LogoNode::init()

    {

        if (!Node::init()) {

            return false;

        }

        _logo=Sprite::create("Saloon (10).png");

        _cocosLogo=Sprite::create("HelloWorld.png");

        

        addChild(_logo);

        addChild(_cocosLogo);

        

        _cocosLogo->setVisible(false);

        

        schedule([this](float f){

            

            _logo->setVisible(!_logo->isVisible());

            _cocosLogo->setVisible(!_cocosLogo->isVisible());

            

        },1,"test");

        return true;

    }

    GameScene:

    #ifndef GameScene_hpp

    #define GameScene_hpp

    #include <stdio.h>

    #include "cocos2d.h"

    USING_NS_CC;

    class GameScene:public Layer

    {

    public:

        GameScene();

        virtual ~GameScene();

        virtual bool init();

        CREATE_FUNC(GameScene);

        static Scene* createScene();

    };

    #endif /* GameScene_hpp */

    #include "GameScene.hpp"

    #include "LogoNode.hpp"

    GameScene::GameScene()

    {

        

    }

    GameScene::~GameScene()

    {

        

    }

    bool GameScene::init()

    {

        if (!Layer::init()) {

            return false;

        }

        auto logo=LogoNode::create();

        addChild(logo);

        

        logo->setPosition(Director::getInstance()->getVisibleSize()/2);

        

        return true;

    }

    Scene* GameScene::createScene()

    {

        auto scene=Scene::create();

        auto layer=GameScene::create();

        

        scene->addChild(layer);

        

        return scene;

    }

  • 相关阅读:
    git 错误 fatal: Not a valid object name: 'master'.
    SQL: select一组数据,concat同表同列的数据
    Linux curl usage
    Regular Expression
    浅谈Linux Process status,环境锁
    浅谈Manpage
    Java文件读写详解。 附txt乱码问题, html乱码问题
    在ubuntu 18.04下装有线守护wg
    centOS 7 换ssh端口
    如何把DEBIAN变成UBUNTU-DESKTOP最少化安装
  • 原文地址:https://www.cnblogs.com/daochong/p/5226204.html
Copyright © 2011-2022 走看看