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中元素是 ...
随机推荐
- redis安装异常的解决的办法
在开始redis安装的时候,先废话一下 官网: 英文 :https://redis.io/ 中文 :http://www.redis.cn/ 首先我们需要一个linux服务器,当然windows也是可 ...
- SpringIOC学习一
Spring是一个轻量级的控制反转(IOC)和面向切面(IOP)的容器框架1.控制反转IOC(inversion of controller) IOC是一种概念,是把我们程序中类与类之间的依赖关 ...
- 机器学习技法:09 Decision Tree
Roadmap Decision Tree Hypothesis Decision Tree Algorithm Decision Tree Heuristics in C&RT Decisi ...
- IO流大总结
- - - - - - - - - - - - - - - 写在前面 - - - - - - - - - - - - - - - 1.概念 IO流用来处理设备之间的数据传输 Java对数据的操作是通过 ...
- Spring Boot简单应用——会员管理系统
简介 本项目是使用Spring Boot编写的一个简单的会员管理系统. 提供了会员的解决方案,主要有会员模块,管理员模块,礼品模块,商品模块,会员等级模块,生日提醒模块,积分模块,详细模块如下图 准备 ...
- spring data学习
在Spring Data模块中定义依赖: <dependencies> <dependency> <groupId>org.springframework.data ...
- Anaconda入门安装教程
Anaconda 是什么? Anaconda 是一个可用于科学计算的 Python 发行版,支持 Linux.Mac.Windows系统,内置了常用的科学计算包.它解决了官方 Python 的两大痛点 ...
- HttpClient入门一
HttpClient是一个实现了Http协议的功能强大的编程工具包. 要使用HttpClient,通常需要以下几部: 1.常见一个HttpClient实例 2.创建一个get或者post方法 3.告诉 ...
- [USACO12JAN]爬山Mountain Climbing
题目描述 Farmer John has discovered that his cows produce higher quality milk when they are subject to s ...
- [洛谷]P3729 曼哈顿计划EX(最小割树/等价流树)
题目大意:给出一张n个点m条边的无向图,每个点有点权,q次询问,每次给出k,要求选出若干个点点权之和不小于k,求一个最大的值x,使得选出的点中任意两点之间至少有x条互不相交的链.(n<=550, ...