本文整理汇总了C++中CCArray::init方法的典型用法代码示例。如果您正苦于以下问题:C++ CCArray::init方法的具体用法?C++ CCArray::init怎么用?C++ CCArray::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCArray
的用法示例。
在下文中一共展示了CCArray::init方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: array_Value
static void array_Value(CCArray * aArray, const cocos2d::ValueVector & value)
{
cocos2d::ValueVector::const_iterator beg = value.begin();
cocos2d::ValueVector::const_iterator end = value.end();
for (; beg != end; ++beg)
{
const Value & v = *beg;
if (v.getType() == Value::Type::MAP)
{
CCDictionary * dict = new CCDictionary();
dict->init();
dictionary_Value(dict, v.asValueMap());
aArray->addObject(dict);
dict->release();
}
else if (v.getType() == Value::Type::VECTOR)
{
CCArray * arr = new CCArray();
arr->init();
array_Value(arr, v.asValueVector());
aArray->addObject(arr);
arr->release();
}
else
{
CCString * str = new CCString();
if (v.getType() == Value::Type::DOUBLE)
str->initWithFormat("%f", v.asDouble());
else
str->initWithFormat("%s", v.asString().c_str());
aArray->addObject(str);
str->release();
}
}
}
示例2: create
CCArray* CCArray::create()
{
CCArray* pArray = new CCArray();
if (pArray && pArray->init())
{
pArray->autorelease();
}
else
{
CC_SAFE_DELETE(pArray);
}
return pArray;
}
示例3: convexHull
//Given a set of points it returns a polygon surrounding those points (a convex hull)
//From here: http://www.algorithmist.com/index.php/Monotone_Chain_Convex_Hull.cpp
CCArray* GameHelper::convexHull(CCArray* P) {
/*int n = P->count();
int k = 0;
CCArray *H = CCArray::create->initWithCapacity(n*2);
//Sort points lexicographically (by X, then secondarily by Y)
NSSortDescriptor *xDescriptor = NSSortDescriptor::alloc()->initWithKey("self.x" , true);
NSSortDescriptor *yDescriptor = NSSortDescriptor::alloc()->initWithKey("self.y" , true);
CCArray *descriptors = CCArray::arrayWithObjects(xDescriptor, yDescriptor, NULL);
CCArray *sortedP = P::sortedArrayUsingDescriptors(descriptors);
//Build lower hull
for (int i = 0; i < n; i ++) {
while (k >= 2 && this->clockwiseO([H , k-2) , H->objectAtIndex(k-1) , sortedP->objectAtIndex(i)]){
k--;
}
H->insertObject([sortedP , i) , k++];
};
//Build upper hull
for (int i = n-2, t = k + 1; i >= 0; i --) {
while (k >= t && this->clockwiseO([H , k-2) , H->objectAtIndex(k-1) , sortedP->objectAtIndex(i)]){
k--;
}
H->insertObject([sortedP , i) , k++];
};
H->removeObjectsInRange(CCRangeMake(k, H.count-k));
//Remove all duplicate objects
CCArray *noDupeArray = CCArray::alloc()->init();
for(int i = 0; i<H.count; i++){
if(!noDupeArray->containsObject(H::objectAtIndex(i))){
noDupeArray->addObject(H::objectAtIndex(i));
}
}*/
CCArray *noDupeArray = CCArray::create();
noDupeArray->init();
return noDupeArray;
}
示例4: findTouchSprite
EditorSprite* EditorLayer::findTouchSprite( cocos2d::CCTouch *pTouch )
{
CCPoint pos = m_containerLayer->convertTouchToNodeSpace(pTouch);
pos = pTouch->getLocation();
CCLOG("position x = %.0f, y = %.0f", pos.x, pos.y);
CCArray* arraySprites = new CCArray();
arraySprites->init();
for (unsigned int i=0; i<m_arraySprite->count(); i++)
{
EditorSprite* pEditorSprite = (EditorSprite*)m_arraySprite->objectAtIndex(i);
if (!pEditorSprite->isTransparentInPoint(pos))
{
arraySprites->addObject(pEditorSprite);
}
}
EditorSprite* pRet = NULL;
if (arraySprites->count() > 0)
{
pRet = (EditorSprite*)arraySprites->objectAtIndex(0);
}
for (unsigned int i=0; i<arraySprites->count(); i++)
{
EditorSprite* pEditorSprite = (EditorSprite*)arraySprites->objectAtIndex(i);
if (pEditorSprite->getOrderForAdd() > pRet->getOrderForAdd())
{
pRet = pEditorSprite;
}
}
arraySprites->removeAllObjects();
delete arraySprites;
return pRet;
}
示例5: dictionary_Value
static void dictionary_Value(CCDictionary * aDict, const cocos2d::ValueMap & value)
{
cocos2d::ValueMap::const_iterator beg = value.begin();
cocos2d::ValueMap::const_iterator end = value.end();
for (; beg != end; ++beg)
{
const std::string & key = (*beg).first;
const cocos2d::Value & v = (*beg).second;
if (v.getType() == Value::Type::MAP)
{
CCDictionary * d = new CCDictionary();
d->init();
dictionary_Value(d, v.asValueMap());
aDict->setObject(d, key);
d->release();
}
else if (v.getType() == Value::Type::VECTOR)
{
CCArray * a = new CCArray();
a->init();
array_Value(a, v.asValueVector());
aDict->setObject(a, key);
a->release();
}
else
{
CCString * str = new CCString();
if (v.getType() == Value::Type::DOUBLE)
str->initWithFormat("%f", v.asDouble());
else
str->initWithFormat("%s", v.asString().c_str());
aDict->setObject(str, key);
str->release();
}
}
}