转载自:http://blog.csdn.net/pleasecallmewhy/article/details/34931021

创建菜单(Menu Item)

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

创建标签(Label)

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

添加精灵(Sprite)

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

精灵动画(Action)

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

添加监听(Listener)

auto listener1 = EventListenerTouchOneByOne::create();

listener1->onTouchBegan = [](Touch* touch, Event* event){
auto target = static_cast<Sprite*>(event->getCurrentTarget());
Point locationInNode = target->convertToNodeSpace(touch->getLocation());
Size s = target->getContentSize();
Rect rect = Rect(0, 0, s.width, s.height);
if (rect.containsPoint(locationInNode))
{
log("sprite began... x = %f, y = %f", locationInNode.x, locationInNode.y);
target->setOpacity(180);
return true;
}
return false;
}; listener1->onTouchMoved = [](Touch* touch, Event* event){
auto target = static_cast<Sprite*>(event->getCurrentTarget());
target->setPosition(target->getPosition() + touch->getDelta());
}; listener1->onTouchEnded = [=](Touch* touch, Event* event){
auto target = static_cast<Sprite*>(event->getCurrentTarget());
if (target == sprite)
{
log("Click on the sprite");
}
}; _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, sprite);

获取屏幕大小(Visible)

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

打印调试(CCLOG)

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

cocos2d-x 3.2,Label,Action,Listener,Menu Item等简单用法的更多相关文章

  1. Difference between menu item types; Display, Output and Action in Dynamics Ax

    Difference between menu item types; Display, Output and Action in Dynamics Ax Developers often ask m ...

  2. [转]NopCommerce How to add a menu item into the administration area from a plugin

    本文转自:http://docs.nopcommerce.com/display/nc/How+to+code+my+own+shipping+rate+computation+method Go t ...

  3. could not execute menu item系统找不到指定的文件

    Wamp3.0.6 64bit,系统任务栏图标,左键,Apache菜单,httpd.conf,报错“could not execute menu item.....系统找不到指定的文件” 根据网上的搜 ...

  4. Editor Scripting学习笔记之Menu Item

    主要用到: MenuItem属性 MenuCommand参数 可能用到: EditorApplication类 Selection类 GameObjectUtility类 FileUtil类 Undo ...

  5. Toolbar 和 CollapsingToolbarLayout一起使用时menu item无点击反应解决办法

    昨天一直在琢磨为什么Toolbar和CollapsingToolbarLayout一起使用时menu item无点击放应的原因,后来在stackoverflow上一条回答,说可能是Toolbar的背景 ...

  6. Func和Action委托简单用法

    Func和Action类是特殊的类型,它们允许你在不必指定自定义委托类型的情况下,去使用委托.在整个.NET框架中都可以使用它们.例如,在我们考察并行计算时,你也会看到这两个类的示例. 上面一段文字是 ...

  7. create-react-app 搭建的项目中,让 antd 通过侧边栏导航 Menu 的 Menu.Item 控制 Content 部分的变化

    第一种:BrowserRouter把Menu和Route组给一起包起来 <Router></Router> 标签要把Menu和Route组给一起包起来 修改src/index. ...

  8. PyQt(Python+Qt)学习随笔:Qt Designer中Action关联menu菜单和toolBar的方法

    1.Action关联菜单 通过菜单创建的Action,已经与菜单自动关联,如果是单独创建的Action,需要与菜单挂接时,直接将Action Editor中定义好的Action对象拖拽到菜单栏上即可以 ...

  9. commandLink/commandButton/ajax backing bean action/listener method not invoked (转)

    Whenever an UICommand component fails to invoke the associated action method or an UIInputelement fa ...

随机推荐

  1. lambda表达式排序

    lambda表达式排序简洁 1.给一个字符串数组: String[] atp = {"2016-06-28 08:00:00", "2017-12-05 19:17:32 ...

  2. jumper-server-部署官网版

    本文链接:https://www.cnblogs.com/wwtao/p/11491574.html 官网链接: https://jumpserver.readthedocs.io/zh/master ...

  3. 如何让基于.NET 2.0的应用在高版本的系统上运行?

    我们的WinForm项目是基于.NET 2.0开发的,在部署时,发现有些机器没有.NET 2.0,但是即使这些机器有装.NET 2.0 以上的版本,也无法运行我们的程序.这就比较蛋疼了. 我们查了一下 ...

  4. java PDF转word的初步实现

    package com.springboot.springboot.util; import java.io.File; import java.io.FileOutputStream; import ...

  5. CentOS7 小技巧总结

    1.CentOS7 解决无法使用tab自动补全 原因:CentOS在最小化安装时,没有安装自动补全的包,需要手动安装. yum -y install bash-completion 安装好后,重新登陆 ...

  6. App引流增长技术:Deeplink(深度链接)技术

    移动互联网时代,信息的分享传播无疑是 App 引流增长的关键,与其花费大量精力和成本找渠道.硬推广,不如从细节下手,用最快最简便的方法实现 Deeplink(深度链接)技术,打破信息孤岛.缩短分享路径 ...

  7. Docker学习之docker架构

    docker架构 解释 1.docker命令提交给docker daemon进行处理,可以拖取镜像,运行容器等等. 2.最右边的实际上是互联网的sass服务,docker daemon可以和Regis ...

  8. 排列组合算法的Java实现

    转载于:http://cgs1999.iteye.com/blog/2327664

  9. 设计模式笔记(一):Singleton 设计模式

    今天开始学习设计模式,借此机会学习并整理学习笔记. 设计模式是一门不区分语言的课程,什么样的编程语言都可以用到设计模式.如果说java语法规则比作武功招式的话,那么设计模式就是心法. 设计模式共有23 ...

  10. 从SpringMVC获取用户信息谈起

    Github地址:https://github.com/andyslin/spring-ext 编译.运行环境:JDK 8 + Maven 3 + IDEA + Lombok spring-boot: ...