如何在数组中存储点
How to store Points in an Array Cocos2d-x C++
我使用Cocos2d-x,我想知道如何在数组中存储点。
myClass.h
Vector<Point*> _pointArray; //Using the cocos class Vector Im getting really confused about how to declare this Points container.
myClass.cpp
//Some trigger in the implementation will populate the array
int count;
int i;
float coinPosX;
float coinPosY;
Point point1 = Vec2(0.8f, 0.2f);
_pointArray.pushBack(point1);
Point point2 = Vec2(15.0f, 10.0f);
_pointArray.pushBack(point2);
count = (int)_pointArray.size();
for (i = 0; i < count; i++){
auto coin = Sprite::create("coin.png");
coin->setPosition(Vec2( _pointArray.at(i).x, _pointArray.at(i).y));
this->addChild(coin);
}
问题是这个错误与pushBack方法:
错误:没有重载函数" cocos2d::Vector::pushback[with T=cocos2d::Sprite*]的实例匹配参数列表
参数类型为(cocos2d::Point)对象类型为cocos2d::Vector;
参数是不正确的,所以我迷路了,这有什么错,什么是正确的方式来存储点在一个数组,我可以迭代并获得它的数据。谢谢你的指导。问候。
不能这样存储。Vector是cocos2d-x,它需要cocos2d-x对象,它扩展Ref类。相反,你可以像这样使用std中的vector(小写):
std::vector<Point> _pointArray;
_pointArray.push_back(point1);
相关文章:
- 使用无符号字符数组有效存储内存
- 如何在cpp.中使用协议缓冲区存储大缓冲区/数组(char/int)
- 在c++中获取两个大int,并将它们存储在数组中
- 使用 Xcode 将双精度存储在数组C++中
- 访问表示 2D 矩阵的 1D 存储数组
- 从输入文件读取整数,仅存储数组C 中的唯一整数
- 如何在队列中存储数组
- 按列主要顺序迭代行大量存储数组
- 如何使存储数组的二进制搜索稳定
- 将行中的字段从textfile中更改为存储数组,而不是重新编写文件
- 存储数组索引值C++
- 存储数组的地方,如果我在返回后声明它
- 缺少存储数组地址的内存
- 使用static在函数中存储数组各个组件的值
- 如何存储数组的每个相邻子数组的和
- 在c++中存储数组映射
- 存储数组的地址列表,以解析原始的非终止文本
- 用于存储数组的字符串
- c++存储数组下一个位置的地址
- 在 for 循环中创建和存储数组