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. [Codeforces 863B]Kayaking

    Description Vadim is really keen on travelling. Recently he heard about kayaking activity near his t ...

  2. HDU 5909 Tree Cutting

    传送门 题意: 有一棵n个点的无根树,节点依次编号为1到n,其中节点i的权值为vi, 定义一棵树的价值为它所有点的权值的异或和. 现在对于每个[0,m)的整数k,请统计有多少T的非空连通子树的价值等于 ...

  3. P3928 SAC E#1 - 一道简单题 Sequence2

    题目背景 小强和阿米巴是好朋友. 题目描述 小强喜欢数列.有一天,他心血来潮,写下了三个长度均为n的数列. 阿米巴也很喜欢数列.但是他只喜欢其中一种,波动数列. 阿米巴把他的喜好告诉了小强.小强便打算 ...

  4. ●BZOJ 3527 [Zjoi2014]力

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3527 题解: FFT求卷积. $$\begin{aligned}E_i&=\frac ...

  5. 51nod 1682 中位数计数

    1682 中位数计数基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均 ...

  6. [HEOI 2016] seq

    题解: 发现多决策且明显无后效性,果断dp,那么转移方程F[i]=F[j]+1 设R[I]为改变之后的最大值,L[i]为改变之后的最小值 由于只能改变一个元素 所以转移的条件是 (j<i &am ...

  7. [BZOJ]1023 cactus仙人掌图(SHOI2008)

    NOIP后的第一次更新嗯. Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人掌图(cactus).所谓简单回路就是指在 ...

  8. poj1741Tree 点分治

    上午学习了点分治,写了1个半小时终于写出一个代码--poj1741,可以说是个模板题. 分治:对于每个儿子找出重心,分别处理 注意:1.每次处理一个重心后,ans减去对它儿子的处理 原因:因为统计方法 ...

  9. Mysql参数汇总

    凡是需要耐心. 参数为静态参数则黄色字体标记. 参数为全局变量则粗体标记. 参数为全局.会话变量则不标记. auto_increment_increment auto_increment_offset ...

  10. Linux 查看系统硬件信息汇总 (部份实例详解Centoso为例)

    1.cpu #lscpu命令,查看的是cpu的统计信息.(部分旧版本不支持) Disk /dev/sda: bytes heads, sectors/track, cylinders Units = ...