下了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. HDU 5614 Baby Ming and Matrix tree 树链剖分

    题意: 给出一棵树,每个顶点上有个\(2 \times 2\)的矩阵,矩阵有两种操作: 顺时针旋转90°,花费是2 将一种矩阵替换为另一种矩阵,花费是10 树上有一种操作,将一条路经上的所有矩阵都变为 ...

  2. Django two

    http://www.cnblogs.com/yuanchenqi/articles/6083427.html Django: 1.安装Django pip install  django 2.创建p ...

  3. C语言变量长度在32位和64位处理器上的关系

    C语言变量长度在32位和64位处理器上的关系       理论上来讲 我觉得数据类型的字节数应该是由CPU决定的,但是实际上主要由编译器决定(占多少位由编译器在编译期间说了算).常用数据类型对应字节数 ...

  4. php处理文件和操作系统

    一.文件和目录 (1).解析目录路径:basename()返回路径的文件名部分 获取路径目录:dirname() 返回除了文件名的路径部分 了解关于路径的更多信息:pathinfo()   返回关联数 ...

  5. [译]pycache是什么?

    原回答: https://stackoverflow.com/questions/16869024/what-is-pycache 当你用python运行一个程序时,解释器首先将它编译成字节码(这是一 ...

  6. 简单使用jstl实现敏感字替换

    package com.ceshi; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; ...

  7. 【bzoj】P4407于神之怒加强版(莫比乌斯反演)

    题目链接 套路一般的枚举$gcd(i,j)=w$.设$min(n,m)=top$,则有 $\sum\limits_{i=1}^{n}\sum\limits_{j=1}{m}gcd(i,j)$ $=\s ...

  8. Django notes III: Dynamic filtering

    EXTRACTED from the Django document It's a common need to filter down the objects given in a list pag ...

  9. HDU——1874畅通工程续(邻接矩阵弗洛伊德)

    畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  10. ACM程序设计选修课——1030: Hungar的时尚球场(水题+耐心)

    1030: Hungar的时尚球场 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 14  Solved: 8 [Submit][Status][Web ...