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中元素是 ...
随机推荐
- StandardContext
错误信息: 2014-2-6 21:37:19 org.apache.catalina.startup.HostConfig checkResources信息: Reloading context [ ...
- OC/Swift/C/C++混合使用的编程姿势
一,OC调用C语言方法 1.OC中的.m文件对C语言完全兼容,可以直接导入C头文件,进行使用 2.定义一个.c的C语言文件,在.m文件中导入,就可以使用. 二,OC调用C++语言方法 1.需要将. ...
- [SPOJ 10628]Count on a tree
Description 题库链接 求不带修改的树上路径第 \(K\) 小. \(N\) 个节点 \(M\) 组询问. \(1\leq N,M\leq 100000\) Solution 主席树维护树上 ...
- [Codeforces 100633J]Ceizenpok’s formula
Description 题库链接 求 \[C_n^m \mod p\] \(1\leq m\leq n\leq 10^{18},2\leq p\leq 1000000\) Solution 一般的 \ ...
- ●BZOJ 2820 YY的GCD
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2820 题解: 莫比乌斯反演 先看看这个题:HDU 1695 GCD(本题简化版) HDU 1 ...
- ●BZOJ 3545 [ONTAK2010]Peaks(离线)
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3545 http://www.lydsy.com/JudgeOnline/problem.ph ...
- NTT+多项式求逆+多项式开方(BZOJ3625)
定义多项式$h(x)$的每一项系数$h_i$,为i在c[1]~c[n]中的出现次数. 定义多项式$f(x)$的每一项系数$f_i$,为权值为i的方案数. 通过简单的分析我们可以发现:$f(x)=\fr ...
- 使用webgl(three.js)搭建一个3D建筑,3D消防模拟——第三课
项目背景 消防安全一直是各大都市关注的重要课题,在消防体系中,特别是高楼消防体系中,消防系统整体布控与监控,火情有效准确定位,防火器材定位,人员逃生路径规划,火情预警,消防演习都是特别重要的环节.所以 ...
- 第一节mysql 安装
1 安装之前的检查 先要检查Linux系统中是否已经安装了MySQL,输入命令尝试打开MySQL服务: 输入密码后,如果出现以下提示,则说明系统中已经安装有 MySQL: 如果提示是这样的,则说明系统 ...
- SQL Server 2008作业失败无法确定所有者是否有服务器访问权限
调用作业---错误提示内容 该作业失败. 无法确定所有者 WIN-3TH1KNIT12D\Administrator (拥有作业 Database_Backup.step1)是否有服务器访问权限 (原 ...