zoukankan      html  css  js  c++  java
  • cocos的helloworld写法

    我觉得吧,做工作是找一份自己喜欢的工作,然后一做很多年,想做安卓就去做,做苹果也去做,现在想转行做游戏,游戏方向有很多,选定前段吧,选定平台COCOS,COOCS有2D和3D,先玩2D吧,写一个helloworld,算是一个新的开始。

    MAC下命令:

    cocos new hellowold -p com.jackjiao -l cpp ~/Desktop。

    选定语言是C++。

    效果图如下。

    代码解读:

    classes文件夹:

     AppDelegate.cpp。

    AppDelegate.h.

    HelloWorldScene.cpp.

    HelloWorldScene.h.

    Resource文件夹:

    放置想要的资源,如图片,字体,arial.ttf.

    cocos2d_libs.xcodeproj文件夹:

    这个是我们的xcode下的cocos框架数据信息。

    Frameworks 文件夹:

    是我们在项目中要用到的框架。

    ios文件夹:

    是我们IOS平台下的文件夹。

    mac:是我们MAC端要用到的文件数据。

    Products:在IOS中,编译运行的时候,会出现一个app文件。用于装载手机上,测试使用。

    和IOS一样,入口是在:

    AppDelegate中,AppDelegate中,这个入口继承了cocos2d::Application项目。

    项目说明了继承cocos,里面有几个方法:

    虚构函数AppDelegate。

    虚函数nitGLContextAttrs():

    现在只能定义6个参数:

    //设置 OpenGL context 属性,目前只能设置6个属性
        //red,green,blue,alpha,depth,stencil
        GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
        GLView::setGLContextAttrs(glContextAttrs);

    appli....

    appli....

    appli...

    这三个函数和IOS一样,就不说明。

    applicationDidFinishLaunching调用方法是在这里面,使用的。

        // initialize director

        auto director = Director::getInstance();

        auto glview = director->getOpenGLView();

        if(!glview) {

    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)

            glview = GLViewImpl::createWithRect("helloworld", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));

    #else

            glview = GLViewImpl::create("helloworld");

    #endif

            director->setOpenGLView(glview);

    }

        // turn on display FPS

        director->setDisplayStats(true);

        // set FPS. the default value is 1.0/60 if you don't call this

        director->setAnimationInterval(1.0f / 60); 

        // Set the design resolution

        glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);

        auto frameSize = glview->getFrameSize();

        // if the frame's height is larger than the height of medium size.

        if (frameSize.height > mediumResolutionSize.height)

        {        

            director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));

        }

        // if the frame's height is larger than the height of small size.

        else if (frameSize.height > smallResolutionSize.height)

        {        

            director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));

        }

        // if the frame's height is smaller than the height of medium size.

        else

        {        

            director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));

        }

        register_all_packages();

        // create a scene. it's an autorelease object

        auto scene = HelloWorld::createScene();

        // run

        director->runWithScene(scene);

        return true;

    解读这段代码数据信息:

  • 相关阅读:
    安全探讨之用Win32汇编写双进程守护
    LightTPD 1.4.12
    mysql4存在mysql5没有的性能成绩
    gcolor2-拾色器
    solaris 中挂载usb移动硬盘
    Browsershots:测试你的 Web 企图
    MythTV 0.20
    XorgEdit:xorg.conf 编纂器
    pci168c,1c无线网卡如何在64位Solaris系统上运用
    Fedora8中批改磁盘卷标
  • 原文地址:https://www.cnblogs.com/jiaoxiangjie/p/6130908.html
Copyright © 2011-2022 走看看