zoukankan      html  css  js  c++  java
  • 第三讲:C++基础语法 & 创建第一个场景 ------学习笔记

    C++语法

    1、在.H(头文件)文件里面进行声明,在CPP文件里面进行定义;

    2、双冒号:: 是一个作用域操作符;

    //自动回收机制,当不用这个类的时候,自动回收

    CREATE_FUNC(HelloWorld);

    如何创建一个最简单的场景:

    新增一个类:

    然后在头文件处输入

    #pragma once
    #include "cocos2d.h"

    using namespace cocos2d;

    class MyScene:public CCLayer
    {
    public:
    MyScene();
    ~MyScene();
    virtual bool init();
    static CCScene* scene();

    CREATE_FUNC(MyScene);
    };

    cpp文件中增加代码:


    CCScene* MyScene::scene()
    {
    // 'scene' is an autorelease object
    auto scene = Scene::create();

    // 'layer' is an autorelease object
    HelloWorld *layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
    }
    bool MyScene::init()
    {
    return true;
    }

    在AppDelegate.cpp文件下修改

    bool AppDelegate::applicationDidFinishLaunching() 下的

    auto scene = MyScene::scene();

    Myscene为新建的类名

  • 相关阅读:
    nexus 手动更改 私服包
    maven 构建时 错误: 程序包netscape.javascript不存在
    RocketMQ
    NSQ
    beego 实现API自动化文档
    动态追踪技术漫谈
    go vendor管理Golang项目依赖
    consul介绍
    golang rpc介绍
    golang 使用os/exec配合context实现的超时机制
  • 原文地址:https://www.cnblogs.com/linguoqiu/p/4802290.html
Copyright © 2011-2022 走看看