hello guys, m stuck with the 2d array implementation through the vectors, since the CCArray has been deprecated but couldn’t find the suitable documentation regarding this…so plz help me out
you can always use the stl
to create an 2d array if that is what you need:
int myArray[3][5];
a 2d vector:
std::vector< std::vector<int> > myVector;
i want to initialise not an int array but an object array. i know how to declare and initialise a 1d vector but only know the declaration for 2d vector and not the initialisation…
So change int to your object?
@slackmoehrle brother u didn’t get my question. I want the initialisation for the last line of your answer, i.e.- std::vector<std::vector> my vector;
There are few different ways like:
std::vector<std::vector<int>> myVec(2, std::vector<int>(3, 4));
Or c++11
std::vector<std::vector<int>> fog {
{ 1, 2, 3 },
{ 4, 5, 6 }
};
2 - first vector dimension
3 - second vector dimension
4- default value
It looks like that:
[4] [4] [4]
[4] [4] [4]
@Edvinas thnx bru…but i did try the same thing prev too but didn’t get the result.
its like cocos2d::Vector<cocos2d::Vectorcocos2d::Sprite>_balls(row,cocos2d::Vectorcocos2d::Sprite(col,NULL))
and the compile time error is–>
No matching constructor for the initialisation of cocos2d::Vectorcocos2d::Sprite
any solution for this bur
if you use cocos2d::Vector()
you can only put items in it that are a type of cocos2d class.
stl::vecttor()
can hold any type.
isn’t sprite a type of cocos2d class, i.e–> cocos2d::sprite
and moreover it is not picking stl whenever i try cocos2d is forced
@Edvinas also tell me how to insert values in 2d vector through at method or if any other method available
it works for me if I use an std::Vector
Well I don’t understand why are you doing it that way, it should work for you, but I don’t see point of doing that
std::vector <std::vector<cocos2d::Sprite>> myVec(4, std::vector<cocos2d::Sprite>(3, *cocos2d::Sprite::create()));
What is the point to initialise vector? Its dynamic you can push back sprites whenever you want. This is how I use vectors for storing sprites std::vector <std::vector <cocos2d::Sprite *>> _TopSprites;
I push back pointer to sprite whenever I want and the if I need something I just go trough vector.
@Edvinas ok i got your point that why to initialise when you can insert afterwards, but bro how to insert a 2d vector?? In case of 1d vector i know like _balls.insert(0,sprite);
or using pushback but can’t get any idea regarding this
And how to retrieve too…
i.e.–> using .at()