1.Cocos2dx 3.2中vector,ValueMap,Touch触摸时间的使用.iconv字符编解码
Cocos2dx3.2以后使用Vector<T>代替了CCArray。案例如下:
|
#ifndef #define #include class { public: CREATE_FUNC(T02Vector); //Cocos2dx3.2以后使用Vector代替了CCArray Vector<Sprite*> bool }; #endif |
|
编写:T02Vector.cpp |
|
#include //in cocos3.2 Vector代替CCArray //如果不是Ref的子类,那不能用Vector,应该用std::vector bool { Layer::init(); Sprite* //增加元素 _arr.pushBack(sprite); //遍历 Vector<Sprite*>::iterator for { Sprite* } for { } for { } //从后往前遍历 for { } //删除 _arr.eraseObject(sprite); return } |
2 Map的用法(注意字符编解码的第三方库有:iconv,cocos中集成的有这方面的功能)
|
头文件:T03Map.h |
|
#ifndef #define #include class public: CREATE_FUNC(T03Map); bool }; #endif |
|
编写:T03Map.cpp |
|
#include /* ValueMap是用来代替cocos2d.x的CCDictionary */ bool { Layer::init(); //内容的加载 ValueMap& //CCDictionary* dict = CCDictionary::createWithContentsOfFile("about.xml"); //const CCString* x = dict->valueForKey("x"); //x->intValue(); //查找 auto if (it { CCLog("can } it = it->first; it->second; CCLog("key CCLog("............................end"); vm["中文"] CCLog("........start //遍历 for (auto { CCLog("key } CCLog("..........................end"); FileUtils::getInstance()->writeToFile(vm, #if 0 // C++11 for (auto { it.first; it.second; } // vm["aa"] // Value& v = 100; vm["bb"] #endif return } |
|
用到的about.xml如下: |
|
<?xml version="1.0" encoding="UTF-8" ?> <plist> <dict> <key>people1</key> <string>许佳音工作室出品</string> <key>people2</key> <string>总监:许佳音</string> <key>people3</key> <string>程序:姜博</string> <key>people4</key> <string>美术:马俊</string> <key>people5</key> <string>改编:班级</string> </dict> </plist> |
3
T04Label的用法
|
头文件:T04Label.h |
|
#ifndef #define #include class public: CREATE_FUNC(T04Label); bool }; #endif |
|
编写:T04Label.cpp |
|
#include bool { Layer::init(); { Label* label->setString("12345"); addChild(label); label->setPosition(winSize.width } #if 0 Label* Label* Label* #endif //Label* label = Label::createWithTexture() return } |
|
运行结果: |
3
T05Touch触摸事件的用法
|
头文件:T05Touch.h |
|
#ifndef #define #include class { public: CREATE_FUNC(T05Touch); bool void }; #endif |
|
编写:T05Touch.cpp |
|
#include bool { Layer::init(); { // EventListenerTouchOneByOne* ev->onTouchBegan // ev->onTouchEnded _eventDispatcher->addEventListenerWithSceneGraphPriority(ev, } #if 0 { // EventListenerTouchOneByOne* ev->setSwallowTouches(true); ev->onTouchBegan _eventDispatcher->addEventListenerWithFixedPriority(ev, } #endif { Sprite* addChild(node); EventListenerTouchOneByOne* ev->onTouchBegan //通过touch->getLocation()的方式获得被选中的点的位置 Vec2 CCLog("Sprite return }; // // ev->onTouchEnded = CC_CALLBACK_2(T05Touch::TouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(ev, } { EventListenerTouchAllAtOnce* ev->onTouchesBegan _eventDispatcher->addEventListenerWithSceneGraphPriority(ev, } return } void } |
1.Cocos2dx 3.2中vector,ValueMap,Touch触摸时间的使用.iconv字符编解码的更多相关文章
- Cocos2d-x中Vector<T>容器以及实例介绍
Vector<T> 是Cocos2d-x 3.x推出的列表容器,因此它所能容纳的是Ref及子类所创建的对象指针,其中的T是模板,表示能够放入到容器中的类型,在Cocos2d-x 3.x中T ...
- Cocos2d-x中Vector<T>容器以及实例介绍
Vector<T> 是Cocos2d-x 3.x推出的列表容器,因此它所能容纳的是Ref及子类所创建的对象指针,其中的T是模板,表示能够放入到容器中的类型,在Cocos2d-x 3.x中T ...
- cocos2dx 3.2中的物理引擎初探(一)
cocos2dx在设计之初就集成了两套物理引擎,它们是box2d和chipmunk.我目前使用的是最新版的cocos2dx 3.2.引擎中默认使用的是chipmunk,如果想要改使用box2d的话,需 ...
- c++中vector的用法详解
c++中vector的用法详解 vector(向量): C++中的一种数据结构,确切的说是一个类.它相当于一个动态的数组,当程序员无法知道自己需要的数组的规模多大时,用其来解决问题可以达到最大节约空间 ...
- cocos2dx 3.7中 AppDelegate.h的class TestController;这种写法的具体意思不太明白,只能猜是类似于外部定义的东西。
cocos2dx 3.7中 AppDelegate.h的class TestController;这种写法的具体意思不太明白,只能猜是类似于外部定义的东西.
- C++的STL中vector内存分配方法的简单探索
STL中vector什么时候会自动分配内存,又是怎么分配的呢? 环境:Linux CentOS 5.2 1.代码 #include <vector> #include <stdio ...
- 解决cocos2dx在Xcode中运行时报:convert: iCCP: known incorrect sRGB profile 的问题
解决cocos2dx在Xcode中运行时报:convert: iCCP: known incorrect sRGB profile 的问题 本文的实践来源是参照了两个帖子完成的: http://dis ...
- cocos2d-x 3.0rc2中读取sqlite文件
cocos2d-x 3.0rc2中读取sqlite文件的方式,在Android中直接读取软件内的会失败.须要复制到可写的路径下 sqlite3* dbFile = NULL; std::string ...
- C++ 中vector的基本用法
//在网上看了好久,自己总结了一下下,第一篇博客,呼呼,学到不少 基本概念 vector容器是一个模板类,可以存放任何类型的对象).vector对象可以在运行时高效地添加元素,并且vector中元素是 ...
随机推荐
- DDCTF 2018线上赛writeup
第一题: d4e8e1f4a0f7e1f3a0e6e1f3f4a1a0d4e8e5a0e6ece1e7a0e9f3baa0c4c4c3d4c6fbb9b2b2e1e2b9b9b7b4e1b4b7e3e ...
- Java IO(一)
在Java中,所有的io类都放在java.io包中. 在IO操作中,我们总是会从一个源数据读取到一个目标数据.那么这个源数据和目标数据可以是文件,流等等.那最常见的就是文件,就像我们在本地电脑上写入东 ...
- ●POJ 2794 Double Patience
题链: http://poj.org/problem?id=2794题解: 状压DP,概率 9元组表示每一堆还剩几张牌.可以用5进制状压,共5^9=1953124个状态. 令P(S)表示S这个状态被取 ...
- VK CUP2017 ROUND 1
来自FallDream的博客.未经允许,请勿转载,谢谢. ---------------------------------------------------- 和ditoly组队打vkcup,原来 ...
- matplotlib中subplot的各参数的作用
subplot(a,b,c)中a代表所画图形的行数 b代表所画图形的列数 c代表所画图形的序号. plt.figure(facecolor='w', figsize=(9, 10)) plt.subp ...
- 如何彻底删除mysql
MySQL的卸载确实很让人头疼,很多时候都无法彻底卸载干净,这样会导致我们无法重新安装新的MySQL. 下面介绍,在Windows10系统下,如何彻底删除卸载MySQL... 1>停止MySQL ...
- final、finally与finalize的区别
1. final 在java中,final可以用来修饰类,方法和变量(成员变量或局部变量).下面将对其详细介绍. 1.1 修饰类 当用final修饰类的时,表明该类不能被其他类所继承.当我们需要让一 ...
- 我在 B 站学机器学习(Machine Learning)- 吴恩达(Andrew Ng)【中英双语】
我在 B 站学机器学习(Machine Learning)- 吴恩达(Andrew Ng)[中英双语] 视频地址:https://www.bilibili.com/video/av9912938/ t ...
- java实现微信支付之扫码支付
本文直接从代码调用微信扫码支付讲起.账号配置,参数生成等请参考官方文档:https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_1 微信 ...
- 读书笔记-《Maven实战》-2018/4/16
第一章:Maven简介 1:Maven:Maven原本的单词意思为"知识的积累",谷歌翻译为"行家",而作为Apache的开源项目,Maven是一个主要服务于基 ...