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;
解读这段代码数据信息:
cocos的helloworld写法的更多相关文章
- cocos2d-x mac os启动 android helloworld
工具环境: mac os, jdk, Android Studio, cocos2d-x-3.13.1, ant, android-ndk. 解压coco2d-x后,根目录下有 setup.py, 命 ...
- cocos基础教程(2)Window环境下搭建
第一步:开始安装VS2012 第二步:下载Cocos2d-x 3.4源码 配置环境变量 COCOS_CONTROL = E:\cocos2d-x-3.4\tools\cocos2d-console ...
- cocos 3.0 一键打包android平台应该注意的细节
cocos2d-x 移植越来越便捷,走到cocos2d-x-3.0rc2,能够说移植已经非常完好了,我们仅仅要进行适当的适配,cocos能够直接帮助我们生成apk 我网络不好无法上传图片:(无图无捷豹 ...
- [COCOS2DX]COCOS命令新建项目+编译安卓项目并成功运行
全程搭建过程参考网址: http://blog.csdn.net/lengxue789/article/details/38116475 http://blog.csdn.net/cbbbc/arti ...
- cocos2d-x新手学习之Helloworld(第三篇)[版本号:cocos2d-x-3.1.1]
上篇中,能够正常执行NDK中的样例.可是由cocos2d-x生成的项目,不能编译成功.上一篇戳这里: http://blog.csdn.net/xjjjjjjjjjjj/article/details ...
- Cocos2d-x_初探_第一次配置与HelloWorld
此前多久,忘了,反正就是打通关泡泡龙以后.YY君向我推荐了这个(如题).一查资料,诶.还挺有意思的,那我就去下一个玩玩吧. 资料下载清单: 1.Android-ndk 2.Android-sdk 3. ...
- HTML5 学习总结(四)——canvas绘图、WebGL、SVG
一.Canvas canvas是HTML5中新增一个HTML5标签与操作canvas的javascript API,它可以实现在网页中完成动态的2D与3D图像技术.<canvas> 标记和 ...
- win7(x64)下安装cocos2d并编译安卓项目
好吧,不为啥,就是如题. win7 x64 脑袋内存比较小,说不定明儿就忘了,今天记录一下. 没有什么经验,所有步骤基本都是百度出来的,这里边操作边记录,为了保护原创作者,这里我都附上我查找的链接. ...
- canvas绘图、WebGL、SVG
目录 一.Canvas 1.1.创建canvas元素 1.2.画线 1.3.绘制矩形 1.4.绘制圆弧 1.5.绘制图像 1.6.绘制文字 1.7.随机颜色与简单动画 二.WebGL 2.1.HTML ...
随机推荐
- java-集合2
浏览以下内容前,请点击并阅读 声明 下面对集中核心集合的接口分别总结 Collection接口 一般情况下,集合的实现类会有一个含有Collection类型为参数的构造器,可以由一个指定的集合类创建该 ...
- grunt 检测js配置
module.exports = function(grunt) { // 项目配置 grunt.initConfig({ pkg: grunt.file.readJSON('package.json ...
- EF 5 最佳实践白皮书
Performance Considerations for Entity Framework 5 By David Obando, Eric Dettinger and others Publish ...
- 小米网站登录源码C#版
一步一步做,肯定能成功 HttpHelper类请从网络上搜索 string postData = getPostData(); HttpHelper ht = new HttpHelper(); Ht ...
- Weblogic部署项目过程中的一些问题
weblogic启动,最后一段出现的警告: <Warning> <Log Management> <BEA-170011> <The LogBroadcast ...
- poj1700-Crossing River(贪心算法)
一,题意: 只有一艘船,能乘2人,船的运行时间为2人中较多一人的时间,过去后还需一个人把船划回来,问把n个人运到对岸,最少需要多久.二,思路步骤: 想办法先把用时最多的2人,运过去,再把剩下来的人中用 ...
- Apache配置过程
要在一台主机上搭建多个网站,最简单的办法就是给不同的网站分配不一样的端口.下面我以Ubuntu 14.04 + Apache 2.4.7为例说一下在搭建过程中的一些注意事项. 1. 主配置文件是/et ...
- spring mvc@RequestParam根据参数名获取传入参数值
在SpringMVC后台控制层获取参数的方式主要有两种,一种是request.getParameter("name"),另外一种是用注解@RequestParam直接获取.这里主要 ...
- Yii源码阅读笔记(三十二)
web/Application类的注释,继承base/Application类,针对web应用的一些处理: namespace yii\web; use Yii; use yii\base\Inval ...
- DataBinding examples
Databinding in Windows Forms demo (CSWinFormDataBinding) /************************************* Modu ...