下了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

最新文章

  1. Android线程管理之Thread使用总结
  2. 预习笔记 多态 --S2 4.3
  3. FreeMarker标签与使用
  4. JS中document对象和window对象有什么区别
  5. Android Service 与 IntentService
  6. pyinstaller打包pyqt文件
  7. 解决:Could not parse response code.Server Reply: SSH-2.0-OpenSSH_5.3
  8. 可输入自动匹配Select——jquery ui autocomplete
  9. Java使用JSP Tag Files & JSP EL Functions打造你自己的页面模板
  10. Hibernate 检索查询的几种方式(HQL,QBC,本地SQL,集成Spring等)
  11. SQL技巧之分类汇总
  12. POJ2299: Ultra-QuickSort-合并排序解决逆序数问题
  13. js原型继承
  14. windows_keyboard shortcuts快捷键
  15. 学习Qt,Getting started
  16. Luogu P2057 [SHOI2007]善意的投票
  17. js弹框的3种方法
  18. Flask 构建微电影视频网站(一)
  19. 对于rqy今天讲座的一些理解和看法吧
  20. github 添加wiki

热门文章

  1. source insight
  2. Linux学习-开放源码的软件安装与升级简介
  3. luogu1939 【模板】矩阵加速(数列)
  4. 从几率到logisitic函数
  5. [svn学习篇]svn使用教程
  6. C语言遇到的小问题
  7. 【java基础 14】锁的粒度:ThreadLocal、volatile、Atomic和Synchronized
  8. 利用Python访问Mysql数据库
  9. 谈谈Python中对象拷贝
  10. fish shell安装和配置