1. CCArray is replaced with Vector<T>.
Vector is clearly faster than CCArray. No need to cast type and preserve the data. Easy to manipulate with overriding functions.
2. std::string + operator
int index = 23;
std::string name = "testSprite" + Value(index).asString() + ".png";
Sprite* spt = Sprite::create(name.c_str());
This works fine on iOS. But it crashes 1 out of 20 times on Android.
3. setUserData
You don't want to cast something to (Void*). It takes too long to cast. The performance will be very lowered. And few more problems will occur like Vector not recognizes it.
4. MotionStreak
It still takes some CPU resources. Don't use it too much.
5. Check my game.
Mr Boss
https://play.google.com/store/apps/details?id=com.magmon.MrBoss
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
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
피드 구독하기:
글 (Atom)
