获取屏幕大小(Visible)

  1. Size visibleSize = Director::getInstance()->getVisibleSize();
  2. Vec2 origin = Director::getInstance()->getVisibleOrigin();

打印调试(CCLOG)

  1. CCLOG("Characters: %c %c", 'a', 65);
  2. CCLOG("Decimals: %d %ld", 1977, 650000L);
  3. CCLOG("Preceding with blanks: %10d", 1977);
  4. CCLOG("Preceding with zeros: %010d", 1977);
  5. CCLOG("Some different radixes: %d %x %o %#x %#o", 100, 100, 100, 100, 100);
  6. CCLOG("Floats: %4.2f %.0e %E", 3.1416, 3.1416, 3.1416);
  7. CCLOG("%s","A string");

创建菜单(Menu Item)

  1. // 创建菜单
  2. auto menuItem = MenuItemImage::create( "MenuNormal.png",
  3. "MenuSelected.png",
  4. CC_CALLBACK_1(HelloWorld::menuCallback, this) );
  5. // 设置坐标
  6. menuItem->setPosition( Vec2(x,y) );
  7. // 创建菜单
  8. auto menu = Menu::create(menuItem, NULL);
  9. menu->setPosition(Vec2::ZERO);
  10. this->addChild(menu, 1);

创建标签(Label)

  1. auto label = LabelTTF::create("Hello World", "Arial", 24);
  2. label->setPosition(Vec2(x,y));
  3. this->addChild(label, 1);

加入精灵(Sprite)

  1. auto sprite = Sprite::create("Me.jpg");
  2. sprite->setPosition(Vec2(visibleSize.width / 2 , visibleSize.height / 2));
  3. sprite->setAnchorPoint(Vec2(0.5,0.5));
  4. this->addChild(sprite, 0);

精灵动画(Action)

  1. auto actionBy = MoveBy::create(1, Point(100,100));
  2. auto easeAction = EaseIn::create(actionBy, 2.5f);
  3. sprite->runAction(Repeat::create(easeAction, 5));

加入监听(Listener)

  1. auto listener1 = EventListenerTouchOneByOne::create();
  2. listener1->onTouchBegan = [](Touch* touch, Event* event){
  3. auto target = static_cast<Sprite*>(event->getCurrentTarget());
  4. Point locationInNode = target->convertToNodeSpace(touch->getLocation());
  5. Size s = target->getContentSize();
  6. Rect rect = Rect(0, 0, s.width, s.height);
  7. if (rect.containsPoint(locationInNode))
  8. {
  9. log("sprite began... x = %f, y = %f", locationInNode.x, locationInNode.y);
  10. target->setOpacity(180);
  11. return true;
  12. }
  13. return false;
  14. };
  15. listener1->onTouchMoved = [](Touch* touch, Event* event){
  16. auto target = static_cast<Sprite*>(event->getCurrentTarget());
  17. target->setPosition(target->getPosition() + touch->getDelta());
  18. };
  19. listener1->onTouchEnded = [=](Touch* touch, Event* event){
  20. auto target = static_cast<Sprite*>(event->getCurrentTarget());
  21. if (target == sprite)
  22. {
  23. log("Click on the sprite");
  24. }
  25. };
  26. _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, sprite);

版权声明:本文博客原创文章。博客,未经同意,不得转载。

[Cocos2d-x]Cocos2d-x 3.2 学习笔记的更多相关文章

  1. cocos2dx游戏开发——微信打飞机学习笔记(三)——WelcomeScene的搭建

    一.场景与层的关系: cocos2dx的框架可以说主要由导演,场景,层,精灵来构成: 1.其中导演,意如其名,就是操控整个游戏的一个单例,管理着整个游戏. 2.场景就像电影的一幕剧情,所以说,懂得如何 ...

  2. android cocos2d-x for Android安装和学习笔记(请用adt-bundle21.1或以上导入)

    引用:http://weimingtom.iteye.com/blog/1483566 (20121108)注意:这篇文章用cdt编译ndk工程的内容已过时(现在可以用adt-bundle,避免配置繁 ...

  3. [Cocos2d-x for WP8学习笔记] HelloWorld结构分析

    先来看一下目录结构: Assets:游戏资源文件,图片音频等,Resource文件夹也有类似功能 include:用于放置游戏头文件 Shaders:渲染器着色器文件(大雾) cocos2dorig. ...

  4. cocos2d-x实战 C++卷 学习笔记--第4章 字符串 __String类

    前言: <cocos2d-x实战C++卷>学习笔记.(cocos2d-x 是3.0版本) 介绍 cocos2d-x 通用的字符串类  __String . 使用cocos2d::__Str ...

  5. Cocos2d-x学习笔记(17)(TestCpp源代码分析-1)

    TestCpp源代码基于Cocos2d-x2.1.3版本号,部分资源来自红孩儿的游戏编程之路CSDN博客地址http://blog.csdn.net/honghaier/article/details ...

  6. 《Cocos2d-x游戏开发实战精解》学习笔记4--实战一个简单的钢琴

    上一节学习了使用Cocos2d-x播放音乐的方法,但是那种方法一般只适合于播放较大的音乐,而一般比较短小的音乐(如游戏中的打斗.按键音效等)则要通过playEffect来播放.本节使用该方法以及之前学 ...

  7. 《Cocos2d-x游戏开发实战精解》学习笔记3--在Cocos2d-x中播放声音

    <Cocos2d-x游戏开发实战精解>学习笔记1--在Cocos2d中显示图像 <Cocos2d-x游戏开发实战精解>学习笔记2--在Cocos2d-x中显示一行文字 之前的内 ...

  8. cocos2d-html5学习笔记(六)--alpha2中cc.Sequence.create中的bug

    cocos2d-html5学习笔记(六)--alpha2中cc.Sequence.create中的bug http://blog.csdn.net/allenice1/article/details/ ...

  9. 【cocos2d-x 3.x 学习笔记】对象内存管理

    内存管理 内存管理一直是一个不易处理的问题.开发人员必须考虑分配回收的方式和时机,针对堆和栈做不同的优化处理,等等.内存管理的核心是动态分配的对象必须保证在使用完成后有效地释放内存,即管理对象的生命周 ...

  10. ‎Cocos2d-x 学习笔记(20) ControlButton

    [Cocos2d-x 学习笔记 目录链接] 1. 简介 ControlButton实现了按钮功能,根据触摸的位置和移动的过程可识别9中EventType类型,执行对应的回调函数. 直接继承了Contr ...

随机推荐

  1. 异常Exception in thread "AWT-EventQueue-XX" java.lang.StackOverflowError

    今天太背了,bug不断,检查到最后都会发现自己脑残了,粗心写错,更悲剧的是写错的时候还不提示错. 刚才有遇到一个问题,抛了这个异常Exception in thread "AWT-Event ...

  2. Test SRM Level Three: LargestCircle, Brute Force

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3005&rd=5858 思路: 如果直接用Brute F ...

  3. poj1163The Triangle(简单DP)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj ...

  4. UIScrollViewA都PI得知。

    //1.设定滚定条的样式 typedef NS_ENUM(NSInteger, UIScrollViewIndicatorStyle) { UIScrollViewIndicatorStyleDefa ...

  5. 客户端上显示csdn上的各类别下的的文章列表 (制作csdn app 三)

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/23597229 今天将在Android 使用Fragment,ViewPagerI ...

  6. CF 452A(Eevee-直接试)

    A. Eevee time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  7. Cocos2d-x学习笔记(六) 定时器Schedule的简单应用

     Cocos2d-x中的定时器使用非常easy,共同拥有3种:schedule.scheduleUpdate和scheduleOnce.简介一下三种的差别: schedule,每隔指定时间运行某个 ...

  8. 如何使用Eclipse API 提供 org.eclipse.wst.wsdl 要解决阅读WSDL档?

    相对而言.Eclipse API中国的数据是比较小的.但Eclipse的API提供了许多的.非常强大. 实例,eclipse的Eclipse API 提供 org.eclipse.wst.wsdl包裹 ...

  9. List、Map和Set实现类

    List.Map和Set实现类 1.List实现类 (1)ArrayList (2)Vector 2.Map实现类 (1)HashMap (2)Hashtable 3.Set实现类 (1)HashSe ...

  10. 探索WebKit核心(一)------ 新秀开始

    为什么WebKit 现在,研究人员WebKit越来越多的人,我不能逃脱,其中还增加.WebKit也多亏了流行的浏览器和WebOS乱斗.随着Palm WebOS, Chrome OS, Firefox ...