首页 技术 正文
技术 2022年11月11日
0 收藏 489 点赞 4,590 浏览 2467 个字

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

MAC下命令:

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

选定语言是C++。

cocos的helloworld写法

效果图如下。

代码解读:

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;

解读这段代码数据信息:

上一篇: Python调用C++
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,488
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289