1. Cocos2dx3.2以后使用Vector<T>代替了CCArray。案例如下:

头文件:T02Vector.h

#ifndef
__T02Vector_H__

#define
__T02Vector_H__

#include
"T32.h"

class
T02Vector
: public
Layer

{

public:

CREATE_FUNC(T02Vector);

//Cocos2dx3.2以后使用Vector代替了CCArray

Vector<Sprite*>
_arr;

bool
init();

};

#endif

编写:T02Vector.cpp

#include
"T02Vector.h"

//in cocos3.2 Vector代替CCArray

//如果不是Ref的子类,那不能用Vector,应该用std::vector

bool
T02Vector::init()

{

Layer::init();

Sprite*
sprite
= Sprite::create();

//增加元素

_arr.pushBack(sprite);

//遍历

Vector<Sprite*>::iterator
it;

for
(it
= _arr.begin();
it
!= _arr.end();
++it)

{

Sprite*
s
= *it;

}

for
(auto
it
= _arr.begin();
it
!= _arr.end();++it)

{

}

for
(auto
it:
_arr)

{

}

//从后往前遍历

for
(auto
it
= _arr.rbegin();
it
!= _arr.rend();++it)

{

}

//删除

_arr.eraseObject(sprite);

return
true;

}

2 Map的用法(注意字符编解码的第三方库有:iconv,cocos中集成的有这方面的功能)

头文件:T03Map.h

#ifndef
__T03Map_H__

#define
__T03Map_H__

#include
"T32.h"

class
T03Map :
public
Layer{

public:

CREATE_FUNC(T03Map);

bool
init();

};

#endif

编写:T03Map.cpp

#include
"T03Map.h"

/*

ValueMap是用来代替cocos2d.x的CCDictionary

*/

bool
T03Map::init()

{

Layer::init();

//内容的加载

ValueMap&
vm =
FileUtils::getInstance()->getValueMapFromFile("about.xml");

//CCDictionary* dict = CCDictionary::createWithContentsOfFile("about.xml");

//const CCString* x = dict->valueForKey("x");

//x->intValue();

//查找

auto
it =
vm.find("aaa");

if (it
== vm.end())

{

CCLog("can
not find aaa");

}

it =
vm.find("people3");

it->first;  
//key:的类型是std::string

it->second; 
//value:的类型是Value,相对cocos3.2.3的CCString

CCLog("key
is %s, value is %s",
it->first.c_str(),
it->second.asString().c_str());

CCLog("............................end");

vm["中文"]
= "bbb";

CCLog("........start
walk over");

//遍历

for (auto
it =
vm.begin();
it !=
vm.end();++it)

{

CCLog("key
is %s,value is %s",it->first.c_str(),it->second.asString().c_str());

}

CCLog("..........................end");

FileUtils::getInstance()->writeToFile(vm,
"new.xml");

#if 0

// C++11

for (auto
it :
vm)

{

it.first;

it.second;

}

//
插入

vm["aa"]
= 10;

//
访问,这种访问有副作用,如果bb节点不存在,它会创建一个bb节点

Value&
v =
vm["bb"];

v = 100;

vm["bb"]
= false;

#endif

return
true;

}

用到的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
__T04Label_H__

#define
__T04Label_H__

#include
"T32.h"

class
T04Label :public
Layer{

public:

CREATE_FUNC(T04Label);

bool
init();

};

#endif

编写:T04Label.cpp

#include
"T04Label.h"

bool
T04Label::init()

{

Layer::init();

{

Label*
label =
Label::createWithCharMap("fonts/Labelatlas.png",
24, 32, '0');

label->setString("12345");

addChild(label);

label->setPosition(winSize.width
/ 2, winSize.height
/ 2);

}

#if 0

Label*
label =
Label::createWithBMFont();

Label*
label =
Label::createWithSystemFont("aaa",
"Arial", 24);

Label*
label =
Label::createWithTTF("");

#endif

//Label* label = Label::createWithTexture()

return
true;

}

运行结果:

3
 T05Touch触摸事件的用法

头文件:T05Touch.h

#ifndef
__T05Touch_H__

#define
__T05Touch_H__

#include
"T32.h"

class
T05Touch :public
Layer

{

public:

CREATE_FUNC(T05Touch);

bool
init();

void
TouchEnded(Touch*,Event
*);

};

#endif

编写:T05Touch.cpp

#include
"T05Touch.h"

bool
T05Touch::init()

{

Layer::init();

{

//
一般使用这种方式,和一个Node相关联

EventListenerTouchOneByOne*
ev =
EventListenerTouchOneByOne::create();

ev->onTouchBegan
= [](Touch*,
Event*){return
true; };

// 
ev->onTouchEnded = [](Touch*, Event*){};

ev->onTouchEnded
= CC_CALLBACK_2(T05Touch::TouchEnded,
this);

_eventDispatcher->addEventListenerWithSceneGraphPriority(ev,
this);

}

#if 0

{

//
固有优先级的方式使用比较少

EventListenerTouchOneByOne*
ev =
EventListenerTouchOneByOne::create();

ev->setSwallowTouches(true);

ev->onTouchBegan
= [](Touch*,
Event*){CCLog("Touch
Begin");
return
true; };

_eventDispatcher->addEventListenerWithFixedPriority(ev,
-128);

}

#endif

{

Sprite*
node =
Sprite::create();

addChild(node);

EventListenerTouchOneByOne*
ev =
EventListenerTouchOneByOne::create();

ev->onTouchBegan
= [](Touch*
touch,
Event*){

//通过touch->getLocation()的方式获得被选中的点的位置

Vec2
pt =
touch->getLocation();

CCLog("Sprite
is touched, pt.x=%f, pt.y=%f",
pt.x,
pt.y);

return
true;

};

// 
ev->onTouchEnded = [](Touch*, Event*){};

// ev->onTouchEnded = CC_CALLBACK_2(T05Touch::TouchEnded, this);

_eventDispatcher->addEventListenerWithSceneGraphPriority(ev,
node);

}

{

EventListenerTouchAllAtOnce*
ev =
EventListenerTouchAllAtOnce::create();

ev->onTouchesBegan
= [](const
std::vector<Touch*>&,
Event*){};

_eventDispatcher->addEventListenerWithSceneGraphPriority(ev,
this);

}

return
true;

}

void
T05Touch::TouchEnded(Touch*,
Event*){

}

1.Cocos2dx 3.2中vector,ValueMap,Touch触摸时间的使用.iconv字符编解码的更多相关文章

  1. Cocos2d-x中Vector<T>容器以及实例介绍

    Vector<T> 是Cocos2d-x 3.x推出的列表容器,因此它所能容纳的是Ref及子类所创建的对象指针,其中的T是模板,表示能够放入到容器中的类型,在Cocos2d-x 3.x中T ...

  2. Cocos2d-x中Vector&lt;T&gt;容器以及实例介绍

    Vector<T> 是Cocos2d-x 3.x推出的列表容器,因此它所能容纳的是Ref及子类所创建的对象指针,其中的T是模板,表示能够放入到容器中的类型,在Cocos2d-x 3.x中T ...

  3. cocos2dx 3.2中的物理引擎初探(一)

    cocos2dx在设计之初就集成了两套物理引擎,它们是box2d和chipmunk.我目前使用的是最新版的cocos2dx 3.2.引擎中默认使用的是chipmunk,如果想要改使用box2d的话,需 ...

  4. c++中vector的用法详解

    c++中vector的用法详解 vector(向量): C++中的一种数据结构,确切的说是一个类.它相当于一个动态的数组,当程序员无法知道自己需要的数组的规模多大时,用其来解决问题可以达到最大节约空间 ...

  5. cocos2dx 3.7中 AppDelegate.h的class TestController;这种写法的具体意思不太明白,只能猜是类似于外部定义的东西。

    cocos2dx 3.7中 AppDelegate.h的class TestController;这种写法的具体意思不太明白,只能猜是类似于外部定义的东西.

  6. C++的STL中vector内存分配方法的简单探索

    STL中vector什么时候会自动分配内存,又是怎么分配的呢? 环境:Linux  CentOS 5.2 1.代码 #include <vector> #include <stdio ...

  7. 解决cocos2dx在Xcode中运行时报:convert: iCCP: known incorrect sRGB profile 的问题

    解决cocos2dx在Xcode中运行时报:convert: iCCP: known incorrect sRGB profile 的问题 本文的实践来源是参照了两个帖子完成的: http://dis ...

  8. cocos2d-x 3.0rc2中读取sqlite文件

    cocos2d-x 3.0rc2中读取sqlite文件的方式,在Android中直接读取软件内的会失败.须要复制到可写的路径下 sqlite3* dbFile = NULL; std::string ...

  9. C++ 中vector的基本用法

    //在网上看了好久,自己总结了一下下,第一篇博客,呼呼,学到不少 基本概念 vector容器是一个模板类,可以存放任何类型的对象).vector对象可以在运行时高效地添加元素,并且vector中元素是 ...

随机推荐

  1. [JSOI 2008]星球大战starwar

    Description 题库链接 给你一张 \(n\) 点, \(m\) 条边的无向图,每次摧毁一个点,问你剩下几个联通块. \(1\leq n\leq 2m,1\leq m\leq 200000\) ...

  2. [HNOI2016]树

    Description 小A想做一棵很大的树,但是他手上的材料有限,只好用点小技巧了.开始,小A只有一棵结点数为N的树,结 点的编号为1,2,…,N,其中结点1为根:我们称这颗树为模板树.小A决定通过 ...

  3. ●BZOJ 1096 [ZJOI2007]仓库建设

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1096 题解: 斜率优化DP $(d_i:i 位置到1位置的距离,p_i:i位置的成品数量,c ...

  4. NOIP2014-11-3模拟赛

    字符串 题目描述 现在给一个字符串,你要做的就是当这个字符串中存在两个挨着的字符是相同的时就将这两个字符消除.需要注意的是,当把这两个字符消除后,可能又产生一对新的挨着的字符是相同的.比如,初始的字符 ...

  5. ●BZOJ 3879 SvT

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3879 题解: 后缀数组,单调栈,RMQ 其实类似 BZOJ 3238 [Ahoi2013]差 ...

  6. [bzoj4906][BeiJing2017]喷式水战改

    来自FallDream的博客,未经允许,请勿转载,谢谢. [题目背景] 拿到了飞机的驾照(?),这样补给就不愁了 XXXX年XX月XX日 拿到了喷气机(??)的驾照,这样就飞得更快了 XXXX年XX月 ...

  7. TDMA over WiFi

    0 引言 TDMA可以修正WiFi中DCF机制中连接速率不同终端间信道占用时间片公平性缺陷,从而提升整体WiFi网络的性能.著名的UBNT的网桥就用其独创的TDMA技术为其赢得了市场.以前是不同的公司 ...

  8. mycat 1.6 简单的操作实例

    环境: centos7.4 + mysql5.7.20 + mycat1.6单台主机上安装了5台mysql_5.7.20 实例(3306,3307,3308,3309,3310)3306为独立实例 ( ...

  9. sql server 表分区

    背景: 一般情况下,我们建立数据库表时,表数据都存放在一个文件里. 但是如果是分区表的话,表数据就会按照你指定的规则分放到不同的文件里,把一个大的数据文件拆分为多个小文件,还可以把这些小文件放在不同的 ...

  10. Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down

    Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offli ...