终于效果图:



Cocos2d-x-3.3 Mac 安装
下载地址:



參考文档: 

在线API列表: 

Cocos2d-x-3.3 版本号
从配置安装到创建项目都是命令行
  • 官网下载最新版本号Cocos2d-x-3.3,大小约为280M
  • watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

    • 解压后,在【终端】中切换文件夹到 解压后的文件夹,然后运行./setup.py,回车,例如以下图所看到的.
    • 期间会有几次询问,是否要设置安卓SDK路径,
    • 假设尚未安装Android开发环境,能够直接Enter跳过,暂不设置
    • (将来  能够在以下的文件里,进行配置:/etc/profile)

1
2
3
 ->Please enter the path of NDK_ROOT (or press Enter to skip):
->Please enter the path of ANDROID_SDK_ROOT (or press Enter to skip):
->Please enter the path of ANT_ROOT (or press Enter to skip):

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

依据提示,敲击命令:
source /Users/history/.bash_profile
然后Enter,这样就算设置好了.

1
Please execute command: "source /Users/history/.bash_profile" to make added system variables take effect
  • 最后就是创建project.
  • 继续命令行
  • cd tools/cocos2d-console/bin,
  • 接着使用以下命令就可以:
  • cocos new project名 -p 包名 -l 语言 -d 目标目录,
  • 比如 :
  • cocos newcocos2d_x -pcom.beyond -lcpp
    -d /Users/beyond/Desktop/project

  • watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

  • 运行后就有例如以下提示,表示OK~
1
2
3
4
5
6
Running command: new
> Copy template into /Users/beyond/Desktop/project/cocos2d_x
> Copying cocos2d-x files...
> Rename project name from 'HelloCpp' to 'cocos2d_x'
> Replace the project name from 'HelloCpp' to 'cocos2d_x'
> Replace the project package name from 'org.cocos2dx.hellocpp' to 'com.beyond'

打开自己主动创建好的项目
能够选择桌面应用,直接command+R,编译执行

等了n分钟过后,最终跑出来了~

兴许补充一下:NDK文件夹的配置
进入终端,输入命令:sudo nano /etc/profile
打开配置环境变量的文件

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

依据实际情况,加入NDK_ROOT、ANT、SDK文件夹
终于,示比例如以下:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">



以下是关于HelloWorld程序分析:
Main.m入口


应用代理AppDelegate.h
#ifndef  _APP_DELEGATE_H_
#define _APP_DELEGATE_H_ #include "cocos2d.h"
/**
@方法说明: The cocos2d Application. The reason for implement as private inheritance is to hide some interface call by Director.
*/
// : private 表示 继承过来的东东,全变成私有
class AppDelegate : private cocos2d::Application
{
public:
// 空參构造函数
AppDelegate();
// 析构函数
virtual ~AppDelegate(); virtual void initGLContextAttrs(); /**
@方法说明: Implement Director and Scene init code here.
@返回: true 初始化成功,应用执行
@返回: false 初始化失败,应用终止
*/
virtual bool applicationDidFinishLaunching(); /**
@方法说明: 应用程序 进入后台后 调用
@參数: the pointer of the application
*/
virtual void applicationDidEnterBackground(); /**
@方法说明: 应用程序 将进入前台时调用
@參数: the pointer of the application
*/
virtual void applicationWillEnterForeground();
}; #endif // _APP_DELEGATE_H_



应用代理AppDelegate.cpp

#include "AppDelegate.h"
#include "HelloWorldScene.h" USING_NS_CC; AppDelegate::AppDelegate() { } AppDelegate::~AppDelegate()
{
} //假设 须要一个不同的 上下文 context,仅仅要改动 glContextAttrs 的值就可以
//it will takes effect on all platforms
void AppDelegate::initGLContextAttrs()
{
//设置 OpenGL context 属性,文件夹仅仅能设置6个属性
//red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8}; GLView::setGLContextAttrs(glContextAttrs);
} bool AppDelegate::applicationDidFinishLaunching() {
// 实例化导演类 director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
// 假设 glview为空,则创建一个
if(!glview) {
glview = GLViewImpl::create("My Game");
director->setOpenGLView(glview);
} // 显示帧率 FPS
director->setDisplayStats(true); // 设置帧率 FPS. 默认就是 1/60秒
director->setAnimationInterval(1.0 / 60); // 创建场景,自己主动释放 it's an autorelease object
auto scene = HelloWorld::createScene(); // 导演执行场景
director->runWithScene(scene); return true;
} // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
Director::getInstance()->stopAnimation(); // if you use SimpleAudioEngine, it must be pause
// SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
} // this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
Director::getInstance()->startAnimation(); // if you use SimpleAudioEngine, it must resume here
// SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}



图层Layer  HelloWorldScene.h

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__ #include "cocos2d.h"
// 事实上是继承自Layer
class HelloWorld : public cocos2d::Layer
{
public:
// cpp里面没有id类型, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene(); // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init(); // 【关闭菜单】点击时的回调方法
void menuCloseCallback(cocos2d::Ref* pSender); // implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
}; #endif // __HELLOWORLD_SCENE_H__<span style="font-family:Courier New;color:#393939;"><span style="font-size: 24px; line-height: 32px; background-color: rgb(245, 245, 245);"><strong>
</strong></span></span>

图层Layer  HelloWorldScene.cpp
#include "HelloWorldScene.h"

USING_NS_CC;

Scene* HelloWorld::createScene()
{
// 'scene' 自己主动释放
auto scene = Scene::create(); // 'layer' 自己主动释放
auto layer = HelloWorld::create(); // 将图层 加入到场景中
scene->addChild(layer); // 返回 填充好图层的 场景
return scene;
} // on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. 调用父类的init , cpp 没有super,直接写父类名
if ( !Layer::init() )
{
return false;
}
// 屏幕尺寸
Size visibleSize = Director::getInstance()->getVisibleSize();
// 2维坐标
Vec2 origin = Director::getInstance()->getVisibleOrigin(); /////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program // add a "close" icon to exit the progress. it's an autorelease object
auto closeItem = MenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1); /////////////////////////////
// 3. add your codes below... // add a label shows "Hello World"
// create and initialize a label auto label = LabelTTF::create("Hello Beyond", "Marker Felt", 50); // position the label on the center of the screen
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height)); // add the label as a child to this layer
this->addChild(label, 1); // add "HelloWorld" splash screen"
auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer
this->addChild(sprite, 0); return true;
} void HelloWorld::menuCloseCallback(Ref* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
return;
#endif Director::getInstance()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}















cocos2d_x_01_环境搭建的更多相关文章

  1. .NET Core系列 : 1、.NET Core 环境搭建和命令行CLI入门

    2016年6月27日.NET Core & ASP.NET Core 1.0在Redhat峰会上正式发布,社区里涌现了很多文章,我也计划写个系列文章,原因是.NET Core的入门门槛相当高, ...

  2. Azure Service Fabric 开发环境搭建

    微服务体系结构是一种将服务器应用程序构建为一组小型服务的方法,每个服务都按自己的进程运行,并通过 HTTP 和 WebSocket 等协议相互通信.每个微服务都在特定的界定上下文(每服务)中实现特定的 ...

  3. rnandroid环境搭建

    react-native 环境搭建具体步骤这个大家已经玩烂了,这个主要是记录下来自己做win7系统遇到的坑 1.com.android.ddmlib.installexception 遇到这个问题,在 ...

  4. python开发环境搭建

    虽然网上有很多python开发环境搭建的文章,不过重复造轮子还是要的,记录一下过程,方便自己以后配置,也方便正在学习中的同事配置他们的环境. 1.准备好安装包 1)上python官网下载python运 ...

  5. springMVC初探--环境搭建和第一个HelloWorld简单项目

    注:此篇为学习springMVC时,做的笔记整理. MVC框架要做哪些事情? a,将url映射到java类,或者java类的方法上 b,封装用户提交的数据 c,处理请求->调用相关的业务处理—& ...

  6. 【定有惊喜】android程序员如何做自己的API接口?php与android的良好交互(附环境搭建),让前端数据动起来~

    一.写在前面 web开发有前端和后端之分,其实android还是有前端和后端之分.android开发就相当于手机app的前端,一般都是php+android或者jsp+android开发.androi ...

  7. Nexus(一)环境搭建

    昨天,成功搭建了自己的 Maven 环境(详见:Maven(一)环境搭建),今天就来研究和探讨下 Nexus 的搭建! 使用背景: 安装环境:Windows 10 -64位 JDK版本:1.7 Mav ...

  8. 「译」JUnit 5 系列:环境搭建

    原文地址:http://blog.codefx.org/libraries/junit-5-setup/ 原文日期:15, Feb, 2016 译文首发:Linesh 的博客:环境搭建 我的 Gith ...

  9. appium+robotframework环境搭建

    appium+robotframework环境搭建步骤(Windows系统的appium自动化测试,只适用于测试安卓机:ios机需要在mac搭建appium环境后测试) 搭建步骤,共分为3部分: 一. ...

随机推荐

  1. Android开发进度03

    1,今日:目标:实现登录界面 2,昨天:实现第一个Android项目Helloworld 3,收获:会使用手机进行测试,会使用SQlite数据库 4,问题:创建项目时出错

  2. webstorm注册码注册

    最近jetbrains公司更新软件总是特别的快,很多私人搭建的server服务也失效了,现出一个能够永久破解的方法,非常简单,只需要2步就完成. 第一步 复制下方activation code,直接粘 ...

  3. 2019-03-18 用Task Schedule定时调用Python脚本

    1.空白处右键新建Task(Create New Task)设置每日定时(Daily) 2.新建Actions 3.填写 Program+Start in 为Python的路径:C:\python36 ...

  4. 小学生都能学会的python(<lamda匿名函数,sorted(),filter(),map(),递归函数>)

    小学生都能学会的python(<<lamda匿名函数,sorted(),filter(),map(),递归函数,二分法>> 1. lambda 匿名函数 lambda 参数: ...

  5. JavaScript变量提升(Hoisting)的小案例

    变量提升(Hoisting)的小案例 执行以下代码的结果是什么?为什么? 答案 这段代码的执行结果是undefined 和 2. 这个结果的原因是,变量和函数都被提升(hoisted) 到了函数体的顶 ...

  6. Http请求和相应模式(B/S)(1)

    B/S模式 服务器端的接受数据 :浏览器端 表单格式 <form></form> GET:请求方式, /index.html  Web浏览器上的资源路径 uname=bjxt& ...

  7. 讲一讲java异常及自定义异常

    1.异常,说白了.两种,一种就是就是不能让代码通过编译的异常.另一种就是程序运行期间出现的异常.异常就是错误,只要出现异常,程序就不会向下运行了.就不会执行后面的代码了.这时候就可以通过显示statc ...

  8. Unsupported major.minor version 51.0问题的解决

    在java编程的过程中,当用myeclipse软件打开别人写的代码时,遇到Unsupported major.minor version 51.0此类问题,实在是令人痛苦不堪.弄了整整一晚才搞清楚,我 ...

  9. Python 获取Google+特定用户最新动态

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-28 @author: guaguastd @name: l ...

  10. m_Orchestrate learning system---十八、mo项目的启示是什么

    m_Orchestrate learning system---十八.mo项目的启示是什么 一.总结 一句话总结:多看教程,体统看教程的学, 完全不懂的话百度的作用也不大 多学点,可以节约后面的超多时 ...