cocos2d-x 3.2,Label,Action,Listener,Menu Item等简单用法
转载自: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等简单用法的更多相关文章
- 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 ...
- [转]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 ...
- could not execute menu item系统找不到指定的文件
Wamp3.0.6 64bit,系统任务栏图标,左键,Apache菜单,httpd.conf,报错“could not execute menu item.....系统找不到指定的文件” 根据网上的搜 ...
- Editor Scripting学习笔记之Menu Item
主要用到: MenuItem属性 MenuCommand参数 可能用到: EditorApplication类 Selection类 GameObjectUtility类 FileUtil类 Undo ...
- Toolbar 和 CollapsingToolbarLayout一起使用时menu item无点击反应解决办法
昨天一直在琢磨为什么Toolbar和CollapsingToolbarLayout一起使用时menu item无点击放应的原因,后来在stackoverflow上一条回答,说可能是Toolbar的背景 ...
- Func和Action委托简单用法
Func和Action类是特殊的类型,它们允许你在不必指定自定义委托类型的情况下,去使用委托.在整个.NET框架中都可以使用它们.例如,在我们考察并行计算时,你也会看到这两个类的示例. 上面一段文字是 ...
- create-react-app 搭建的项目中,让 antd 通过侧边栏导航 Menu 的 Menu.Item 控制 Content 部分的变化
第一种:BrowserRouter把Menu和Route组给一起包起来 <Router></Router> 标签要把Menu和Route组给一起包起来 修改src/index. ...
- PyQt(Python+Qt)学习随笔:Qt Designer中Action关联menu菜单和toolBar的方法
1.Action关联菜单 通过菜单创建的Action,已经与菜单自动关联,如果是单独创建的Action,需要与菜单挂接时,直接将Action Editor中定义好的Action对象拖拽到菜单栏上即可以 ...
- 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 ...
随机推荐
- 上传文件的C#代码
1 <%@ WebHandler Language="C#" Class="UpLoadFile" %> 2 3 using System; 4 u ...
- 为什么有的编程规范要求用 void 0 代替 undefined
Undefined Undefined 类型表示未定义,它的类型只有一个值,就是 undefined. 任何变量在被赋值前它的值都是 undefined,但是在 JavaScript 引擎中,unde ...
- 原创 | 手摸手带您学会 Elasticsearch 单机、集群、插件安装(图文教程)
欢迎关注笔者的公众号: 小哈学Java, 每日推送 Java 领域干货文章,关注即免费无套路附送 100G 海量学习.面试资源哟!! 个人网站: https://www.exception.site/ ...
- 在线扩容LV卷
1.登陆VC,添加硬盘 2.登陆到Linux主机 3.在线扫盘 [root@cnsz22pl0074:/root]# echo "- - -" > /sys/class/sc ...
- [大数据学习研究] 4. Zookeeper-分布式服务的协同管理神器
本来这一节想写Hadoop的分布式高可用环境的搭建,写到一半,发现还是有必要先介绍一下ZooKeeper这个东西. ZooKeeper理念介绍 ZooKeeper是为分布式应用来提供协同服务的,而且Z ...
- STL中区间最值max_element和min_element的用法
前面的博客已经讲解了nth_element寻找区间第K大的用法,现在我们来说说这两个找区间最值的用法.两个函数都包含在algorithm库中. 一.函数原型 max_element template& ...
- 强大的时间处理库 moment
中文文档: http://momentjs.cn/docs/ 常用方法 1.当前时间对象 moment () / 指定时间对象 moment("2019-09-19 08:00:0 ...
- 多线程编程学习十一(ThreadPoolExecutor 详解).
一.ThreadPoolExecutor 参数说明 public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keep ...
- mybatis if判断两个值是否相等存在的坑啊
1.使用“==”比较 字符类型 的值 用“==”比较的使用场景: 不管你用的什么类型的变量,只要变量的值是字符类型就用“==” 产生原因: 在mybatis中如果<if>标签用一个“=”判 ...
- PTA A1014
A1014 Waiting in Line (30 分) 题目内容 Suppose a bank has N windows open for service. There is a yellow l ...