I Am a newbie to Cocos2d-x.I want to know how to create a dynamic array and insert integer values to it .These integer values will be created at runtime.Any help is beneficial.
Very basic Cocos2d-x style dynamic array with int values, a loop and a debug print.
This is for 2.1.x
CCArray* dynamicArray = CCArray::create();
dynamicArray->retain();
dynamicArray->addObject(CCInteger::create(2));
dynamicArray->addObject(CCInteger::create(7));
dynamicArray->addObject(CCInteger::create(12));
CCObject* obj;
CCARRAY_FOREACH(dynamicArray, obj) {
CCInteger* value = (CCInteger*)obj;
CCLOG("%d was in the array", value->getValue());
}
CC_SAFE_RELEASE_NULL(dynamicArray);
Enjoy the output …
2 was in the array
7 was in the array
12 was in the array
1 Like
You can also use “classic” C++ arrays and other dynamic structures (std::vector for example).