mardi 13 mai 2014

Object Pools in Cocos2D-X v3.0 Final - Deprecated CCArray


Vote count:

0




In the search for true randomness using cocos2d-X, without the need of excessive conditionals; the algorithm of interest utilizes 2 CCArray(s) to allocate and combine functions on two different object pools.


We Create a 'pool' for an object 'leather' and 'leatherSelection'. We Overwrite CCSprite with a custom class named 'SaddleManifold'


/**


On the header, using deprecated Cocos2D-x define an array of 'leather' types.



CCArray * _leather;
CCArray * _leatherSelection;


The use of CCArray is obviously unfit for the new cocos2D-x library. I am looking for ways to re-write my code using the new cocos2D-X V3 library which introduces vectors.



/** Destroyer **/
SaddleManifold::~SaddleManifold() { }

/**implementation class **/

_leather = CCArray::createWithCapacity(5);
_leather->retain();

//Attempt to overload

_leatherSelection = CCArray::createWithCapacity(4);
_leatherSelection->retain();

/** I get thrown an 'out-of-line' definition when building this signature **/
void SaddleManifold::initSaddleManifold(Saddle * saddle) {

.....}


Now if I try this:



/* Saddle is a Sprite! */

Saddle * saddle;

/*set boundaries*/
while (currentSaddletWidth < _minSaddleManifoldWidth) {


The saddle chooses randomly from an array of leather types. Here's an excerpt of the code in question:



saddle = (Saddle *) _leatherArray->objectAtIndex(_leatherArrayIndex);
_leatherArrayIndex+;

/**this does not run since it relies on that deprecated count()**/

if (_leatherArrayIndex == _leatherArray> count()) {
_leatherArrayIndex =0;
}

this->initSaddleManifold(saddle);

/** width assignment differential **/
currentSaddleWidth += saddle->getWidth();

_leatherSelection->addObject(obstacle);


Which would be the best way to transition from



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire