How to use vector in cocos2d-x?

Hi again!
How to use Vectors in cocos2d-x now when you can’t use array…

Something like how to add object and should i retain and when to release object from the vector and those sort of stuff>?

Thanks x100000!

I use std::vector for this and push_back() to put whatever Cocos2d-x object type I told it that it would be housing…

cocos2d::Vector can be used with any derivation of cocos2d::Ref to retain and release on addition to or deletion from the container. So you don’t need to do it yourself when using this type.

See the implementation for further details

1 Like

Thanks to both of you for the quick replies!
But ain’t it stupid that you need to download additional files(if you will get the auto release and so on)just because e developers removed the arrays?

If I’m wrong, can you explain more @almax27
Thanks!

I am sorry, I don’t follow what you mean here…

Sorry, what additional files? std::vector is a standard library type that will be bundled with your compiler, and cocos2d::Vector is part of the cocos2d-x API you should have in its entirety. The link I posted was to the cocos2d-x github, it is not a file that is meant to be downloaded on it’s own.

Thanks to you both!
I got it!