Hi I want to save CCPoint to my array? Any simple solution guys? Thanks in advance…
Hi, CCArray only supports CCObject or its subclass. If you really want to achieve that, you should modify CCPoint’s implementation. Make it inherit CCObject.
i use ccpointarray to store the ccpoint, but i can’t remove the ccpoint in the ccpointarray. i want to implements a function like removeallobjects in carray, so i use a for loop, and in the loop i use remove control points, but it doesn’t work?
Wouldn’t an std::vector or an std::list suffice?
I personally use CCArray for CCObject subclasses and std::vector for non-cocos2d-x objects.
thanks,in fact this is also my solution for this problem now, i think the CCPointArray is so useless, may be it will be improved sometime.
how do you use ccpoint with std ::vector ? i think std::vector use only pointer example :
std::vector<CCpoint*> nodes;
Does anyone know a way to permutate a CCPointArray ?
I tried CCARRAY_FOREACH(…) { …. }
but doesn’t work with CCPointArray
Orlando Soto wrote:
Does anyone know a way to permutate a CCPointArray ?
I tried CCARRAY_FOREACH(…) { …. }
but doesn’t work with CCPointArray
I would just iterate using a normal ‘for’ loop
CCPointArray *pointArray = CCPointArray::create(255);
for(int i = 0; i < 10; i++){
pointArray->addControlPoint(ccp(i,i));
}
for(int i = 0; i < pointArray->count(); i++){
CCPoint point = pointArray->getControlPointAtIndex(i);
CCLog("(%f,%f)", point.x, point.y);
}
If you want something like CCARRAY_FOREACH
you can add this (based on CCARRAY_FOREACH from CCArray.h)
#define CCPOINTARRAY_FOREACH(__array__, __object__) \
if ((__array__) && (__array__)->count() > 0) \
for(int __arr__ = 0; \
(__arr__ <= __array__->count()) && \
((__object__ = __array__->getControlPointAtIndex(__arr__)).equals(__object__)); \
__arr__++)
If you want to change the name to something like CCPARRAY_FOREACH, go ahead.
I would keep it uppercase though because it denotes macros.
You can use it in the same fashion
CCPointArray *pointArray = CCPointArray::create(255);
for(int i = 0; i < 10; i++){
pointArray->addControlPoint(ccp(i,i));
}
CCPoint point;
CCPOINTARRAY_FOREACH(pointArray, point){
CCLog("(%f,%f)", point.x, point.y);
}