下了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. linux学习-用户的特殊 shell 与 PAM 模块

    特殊的 shell, /sbin/nologin 『无法登入』指的是:『这个使用者无法使用 bash 或其他 shell 来登入系统』而已, 并不是说这个账号就无法使用其他的系统资源! 让某个具有 / ...

  2. Java线程和多线程(四)——主线程中的异常

    作为Java的开发者,在运行程序的时候会碰到主线程抛异常的情况.如果开发者使用Java的IDE比如Eclipse或者Intellij IDEA的话,可能是不需要直接面对这个问提的,因为IDE会处理运行 ...

  3. HDU 2460 Network 边双连通分量 缩点

    题意: 给出一个无向连通图,有\(m\)次操作,每次在\(u, v\)之间加一条边,并输出此时图中桥的个数. 分析: 先找出边双连通分量然后缩点得到一棵树,树上的每条边都输原图中的桥,因此此时桥的个数 ...

  4. Linux inode 之我见

    Linux硬盘组织方式为:引导区.超级块(superblock),索引结点(inode),数据块(datablock),目录块(diredtory block).其中超级块中包含了关于该硬盘或分区上的 ...

  5. MyBatis多个接口参数报错:Available parameters are [0, 1, param1, param2], 及解决方法

    1. sql语句如下: SELECT * FROM tb_crm_user WHERE id = #{userId, jdbcType=INTEGER} AND user_name = #{userN ...

  6. day01_02.php的开发环境准备

    PHP开发环境的准备 此套课程推荐xampp,也就是Apache+Mysql+PHP 但是我自己的机器装的是wamp环境,稍微有一些不一样,但是不影响使用

  7. dubbo控制台在tomcat上的部署

    1.下载dubbo-admin的war包,比如dubbo-admin-2.5.4.war 2.因为在tomcat上部署,所以务必确认安装了JDK和tomcat,以及配置好了环境变量. 3.将dubbo ...

  8. Java分页内容实例详解

    首先定义一个fruit表,表里含有很多数据: 定义一个数据文件: public class Fruit { public String getIds() { return ids; } public ...

  9. python相关——如何安装pip

    今天在新的一台电脑上安装了pip.流程有点忘记了,在这里再次记录下来. 本教程基于python3.4,并且需要连接互联网,总共需要两步. 1.要安装pip,首先要安装setuptools,链接:htt ...

  10. 设计模式(十九)观察者模式 Observer

    模拟场景: 甲方提供了一个气象站的接口,气象站上面装有:温度感应装置.湿度感应装置.气压感应装置. 现在我们是乙方,需要设计一个 WeatherData 对象,从气象站获取数据,并且利用这些数据,更新 ...