Diego Diego - 1 year ago 198
C++ Question

How to store Points in an Array Cocos2d-x C++

I'm using Cocos2d-x and I would like to know how to store Points in an array.

Vector<Point*> _pointArray; //Using the cocos class Vector Im getting really confused about how to declare this Points container.


//Some trigger in the implementation will populate the array
int count;
int i;
float coinPosX;
float coinPosY;

Point point1 = Vec2(0.8f, 0.2f);

Point point2 = Vec2(15.0f, 10.0f);

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));


The problem is this error with the pushBack method:

Error: No instance of overloaded function ‘’cocos2d::Vector::pushback[with T=cocos2d::Sprite*]
matches the argument list

arguments types are(cocos2d::Point)
object type is cocos2d::Vector;

The argument is not right, so I¡m getting lost, Whats wrong with this, and whats the right way to store Points in an array that I can iterate and get its data. Thanks for any guideline . Greetings.

Answer Source

You can't store it like this. Vector is cocos2d-x which requires cocos2d-x objects, which extend Ref class. Instead you can use vector (lower case) like this:

vector<Point> _pointArray;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download