2014년 7월 10일 목요일

Cocos2d-x 3.0 [Vector] How to use Vector instead of CCArray

Cocos2d-x 3.0 has changed CCArray class to Vector<T>. It's basically from the std::vector<T>. But more familiar and easy to use.

Vector is not a pointer so you have to use '.' instead of '->'

cocos2d-x 2.0 uses CCArray which was easy but low performance. Vector clearly shows higher performance.

Below is simple example about how to use the vector in cocos2d-x 3.0.

Have fun coding with cocos2d-x and vector.


Vector<Sprite*> spriteArray;

spriteArray.pushBack(Sprite::create("LegendDary.png"));

int index = 0;
Sprite* sptFromVector = spriteArray.at(index);

spriteArray.eraseObject(sptFromVector);

for(int i = 0;i < spriteArray.size(); i++){
   Sprite* spt = spriteArray.at(i);
}

for(auto spt: spriteArray){
    Point pos = spt->getPosition();
}




Check out my game :p

Mr Boss

https://play.google.com/store/apps/details?id=com.magmon.MrBoss


댓글 없음:

댓글 쓰기