下了cocos2d-x 源码,开搞!

首先,笔者本身

1)      5年没有摸过c++了

2)     没用过cocos2d-x

3)      有强烈的求知欲望(这条每个简历个人介绍不都这么写么,哈哈)

来开搞!

首先运行cocos源码,笔者vs2013打开的

喏,有图有真相

cpptest和emptytest都是能运行的,直接运行,编译直接过的,咱们说的是emptytest,也就是说空项目的那个,原因很简单,cpptest编译慢,empty快,哈哈

这是运行的界面,恩,然后。我们看一下代码:

首先,AppDelegate这个类,是一个类似于入口函数的东西,我暂且叫他这个东西,然后,我们找到

    // set searching path
FileUtils::getInstance()->setSearchPaths(searchPath); // 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.0 / ); // create a scene. it's an autorelease object
auto scene = HelloWorld::scene();
auto fish = FishTestScence::scene();
// run
director->runWithScene(scene); return true;

这里,auto scene就是它自带的HelloWorld::Scence的一个例子画布,

 director->runWithScene(scene);

这里,就是显示当前的场景,然后进入HelloWorldScene.cpp中

bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
} auto visibleSize = Director::getInstance()->getVisibleSize();
auto origin = Director::getInstance()->getVisibleOrigin(); /////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it. // 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(origin + Vec2(visibleSize) - Vec2(closeItem->getContentSize() / )); // create menu, it's an autorelease object
auto menu = Menu::create(closeItem, nullptr);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, ); /////////////////////////////
// 3. add your codes below... // add a label shows "Hello World"
// create and initialize a label auto label = LabelTTF::create("Hello World", "Arial", TITLE_FONT_SIZE); // position the label on the center of the screen
label->setPosition(origin.x + visibleSize.width/,
origin.y + visibleSize.height - label->getContentSize().height); // add the label as a child to this layer
this->addChild(label, ); // add "HelloWorld" splash screen"
auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize / ) + origin); // add the sprite as a child to this layer
this->addChild(sprite); return true;
}

这段代码就是它显示在界面上的一个label和一个image,什么 setposition 什么addchild啦,这些每一个程序狗都是能看懂的

大概就是这个样子。

然后呢,作为一个有尊严的程序狗,我不能老是照抄源码吧,你要写一些自己的东西,然后,笔者照猫画虎写了两个文件

FishTestScence.h 和FishTestScence.cpp

内容会传上去

我在 画布上花了一个button ,和一个简单的图片,然后鼠标点击button事件的触发,

bool FishTestScence::init()
{
if (!Scene::init())
{
return false;
} auto visibleSize = Director::getInstance()->getVisibleSize();
auto origin = Director::getInstance()->getVisibleOrigin(); auto button = ui::Button::create("dangban.png", "ball.png"); button->setPosition(Vec2(visibleSize / ) + origin);
button->setPressedActionEnabled(true);
button->setTitleText("lou zhu sb"); button->addTouchEventListener(CC_CALLBACK_2(FishTestScence::onButtonClicked, this));
this->addChild(button); return true;
}

这是我照猫画虎的代码

点击button 然后能够接收到按钮的click事件

感觉还是不错的,毕竟只是花了一天时间开始试着搞

友情提示:ball.png和dangpan.png这两张图片如果读取不对,你要跟一下他的那个读取函数,看filepath然后把图片放到路径下

源代码:test.rar

cocos2d-x step by step(1) First Blood的更多相关文章

  1. Step by step Dynamics CRM 2011升级到Dynamics CRM 2013

    原创地址:http://www.cnblogs.com/jfzhu/p/4018153.html 转载请注明出处 (一)检查Customizations 从2011升级到2013有一些legacy f ...

  2. Step by Step 创建一个新的Dynamics CRM Organization

    原创地址:http://www.cnblogs.com/jfzhu/p/4012833.html 转载请注明出处 前面演示过如何安装Dynamics CRM 2013,参见<Step by st ...

  3. Step by step Install a Local Report Server and Remote Report Server Database

    原创地址:http://www.cnblogs.com/jfzhu/p/4012097.html 转载请注明出处 前面的文章<Step by step SQL Server 2012的安装 &g ...

  4. Step by step Dynamics CRM 2013安装

    原创地址:http://www.cnblogs.com/jfzhu/p/4008391.html 转载请注明出处   SQL Server可以与CRM装在同一台计算机上,也可安装在不同的计算机上.演示 ...

  5. Step by step 活动目录中添加一个子域

    原创地址:http://www.cnblogs.com/jfzhu/p/4006545.html 转载请注明出处 前面介绍过如何创建一个域,下面再介绍一下如何在该父域中添加一个子域. 活动目录中的森林 ...

  6. SQL Server 维护计划实现数据库备份(Step by Step)(转)

    SQL Server 维护计划实现数据库备份(Step by Step) 一.前言 SQL Server 备份和还原全攻略,里面包括了通过SSMS操作还原各种备份文件的图形指导,SQL Server  ...

  7. 转:eclipse以及step into step over step return的区别

    首先来讲一下step into step over step return的区别: step into就是单步执行,遇到子函数就进入并且继续单步执行:(F5) step over是在单步执行时,在函数 ...

  8. [转]Bootstrap 3.0.0 with ASP.NET Web Forms – Step by Step – Without NuGet Package

    本文转自:http://www.mytecbits.com/microsoft/dot-net/bootstrap-3-0-0-with-asp-net-web-forms In my earlier ...

  9. EF框架step by step(7)—Code First DataAnnotations(2)

    上一篇EF框架step by step(7)—Code First DataAnnotations(1)描述了实体内部的采用数据特性描述与表的关系.这一篇将用DataAnnotations描述一下实体 ...

  10. EF框架step by step(6)—处理实体complex属性

    上一篇的中介绍过了对于EF4.1框架中,实体的简单属性的处理 这一篇介绍一下Code First方法中,实体Complex属性的处理.Complex属性是将一个对象做为另一个对象的属性.映射到数据库中 ...

随机推荐

  1. win7创建共享给windows和linux机器

    win7创建共享给windows和linux机器   1 防火墙 允许网络共享 由nod32负责防火墙设置 2 修改主机名 3 修改工作组和域 4 设置共享用户和权限 5 查看本机所有共享

  2. 打造一款属于自己的web服务器——从简单开始

    距离开篇已经过了很久,期间完善了一下之前的版本,目前已经能够完好运行,基本上该有的功能都有了,此外将原来的测试程序改为示例项目,新项目只需按照示例项目结构实现controller和view即可,详情见 ...

  3. android adb虚拟机对应的键盘命令

    HOME                               Home button 主界面键 F2, PAGEUP                      Menu (Soft-Left) ...

  4. python - work5 - 类与对象 - 拓展题

    ''' 5:购物车类,包含的功能如下,请自行设计这个类以及类里面的方法:1)用户输入工资后,打印商品列表(商品列表自行设计展示模式)2)允许用户根据商品编号去选择商品3)用户选择商品后,检查余额是否足 ...

  5. 【LeetCode】Binary Tree Inorder Traversal(二叉树的中序遍历)

    这道题是LeetCode里的第94道题. 题目要求: 给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单 ...

  6. 爬虫Scrapy框架-2爬取网站视频详情

     爬取视频详情:http://www.id97.com/ 创建环境: movie.py 爬虫文件的设置: # -*- coding: utf-8 -*- import scrapy from movi ...

  7. SQLSERVER中文日期varchar格式转换成datetime格式

    因项目要求,需要把SQLSERVER一张客户表的数据同步到oracle库的一张客户表,但两张表有时间类型不一致,需要进行转换 如下: SELECT CUSTCODE,AgreementValidity ...

  8. 使用runtime关联对象将视图添加到视图的类目里

    //get方法 - (RJCircularLoaderView*)rj_circularLoaderView { RJCircularLoaderView *loaderView = objc_get ...

  9. 算法复习——背包dp

    1.01背包 二维递推式子: 代码: ;i<=n;i++) ;x--) ][x-w[i]]+c[i],f[i-][x]); ][x]; printf("%d",f[n][m] ...

  10. PAT 甲级 1003. Emergency (25)

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...