zoukankan      html  css  js  c++  java
  • cocos2dx一个场景添加多个层

    首先创建两个layer,以下是头文件

    #pragma once
    #include "cocos2d.h"
    USING_NS_CC;
    class BackgroundLayer : public cocos2d::CCLayer
    {
    public:
    virtual bool init();
    CREATE_FUNC(BackgroundLayer);
    };

    #pragma once
    #include "cocos2d.h"
    USING_NS_CC;
    class FishLayer : public cocos2d::CCLayer
    {
    public:
    virtual bool init();
    CREATE_FUNC(FishLayer);
    };

     

    现在去源文件实现一下:

    #include "BackgroundLayer.h"
    bool BackgroundLayer::init()
    {
    CCSprite* bg = CCSprite::create("bg.png");
    bg->setPosition(ccp(visiblesize.width/2, visiblesize.height/2));
    addChild(bg);
    return true;
    }

    #include "FishLayer.h"
    bool FishLayer::init()
    {
    CCSprite* bg = CCSprite::create("bgfish.png");
    bg->setPosition(ccp(visiblesize.width/2, visiblesize.height/2));
    addChild(bg);
    return true;
    }

    ok,现在已经有了两个层了,建一个scene并添加他们:

    #pragma once
    #include "cocos2d.h"
    #include "FishLayer.h"
    #include "BackgroundLayer.h"
    class GameScene : public cocos2d::CCScene
    {
    public:
    virtual bool init();
    static CCScene* playGame();
    };


    去源文件添加啦:

    #include "GameScene.h"
    CCScene* GameScene::playGame()
    {
    GameScene* scene = new GameScene();
    scene->init();
    return scene;
    }
    bool GameScene::init()
    {
    BackgroundLayer* pLayer_bg = BackgroundLayer::create();
    FishLayer* pLayer_fish = FishLayer::create();
    addChild(pLayer_bg);
    addChild(pLayer_fish);
    return true;
    }

    ok,现在场景里面已经有两个层了,可以分别在这两个层里添加东西了。

  • 相关阅读:
    <二>基于Django 简单后台管理页面
    单页面中使用vue和iview、echarts,引用组件
    vuecli更新
    vuex promise async await
    vue父子组件之间传值
    常用正则
    vue项目利用loadsh实现防抖和节流
    vue项目实现按钮的权限
    使用内存虚拟硬盘 提高ArcGIS server并发性能的一种方法
    esri联邦用户大会 总结
  • 原文地址:https://www.cnblogs.com/ADaii/p/3779985.html
Copyright © 2011-2022 走看看