本文整理汇总了C++中CCMutableArray类的典型用法代码示例。如果您正苦于以下问题:C++ CCMutableArray类的具体用法?C++ CCMutableArray怎么用?C++ CCMutableArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCMutableArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cacheAnimations
void AnimatableDecorator::cacheAnimations() const {
for (Value animationValue : animations()) {
{
Array<Value> frames = animationValue.mapValue()["frames"].arrayValue();
CCMutableArray<CCSpriteFrame*>* spriteFrames = new CCMutableArray<CCSpriteFrame*>();
spriteFrames->autorelease();
for (Value frame : frames) {
CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frame.string().c_str());
spriteFrames->addObject(spriteFrame);
}
float delay = animationValue.mapValue()["delay"].floatValue();
CCAnimation* animation = CCAnimation::animationWithFrames(spriteFrames, delay);
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, animationValue.mapValue()["name"].string().c_str());
}
}
}
示例2: removeSpriteFromAtlas
void CCSpriteBatchNode::removeSpriteFromAtlas(CCSprite *pobSprite)
{
// remove from TextureAtlas
m_pobTextureAtlas->removeQuadAtIndex(pobSprite->getAtlasIndex());
// Cleanup sprite. It might be reused (issue #569)
pobSprite->useSelfRender();
unsigned int uIndex = m_pobDescendants->getIndexOfObject(pobSprite);
if (uIndex != -1)
{
m_pobDescendants->removeObjectAtIndex(uIndex);
// update all sprites beyond this one
unsigned int count = m_pobDescendants->count();
for(; uIndex < count; ++uIndex)
{
CCSprite* s = (CCSprite*)(m_pobDescendants->getObjectAtIndex(uIndex));
s->setAtlasIndex( s->getAtlasIndex() - 1 );
}
}
// remove children recursively
CCMutableArray<CCNode*> *pChildren = pobSprite->getChildren();
if (pChildren && pChildren->count() > 0)
{
CCSprite *pSprite;
CCMutableArray<CCNode*>::CCMutableArrayIterator iter;
for (iter = pChildren->begin(); iter != pChildren->end(); ++iter)
{
pSprite = (CCSprite*)(*iter);
if (! pSprite)
{
break;
}
removeSpriteFromAtlas(pSprite);
}
}
}
示例3: daZhaoEffect
void GamingLayer::daZhaoEffect()
{
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
CCMutableArray<CCSpriteFrame*>* animFrames = new CCMutableArray<CCSpriteFrame*>(4);
char str[20] = {};
for (size_t i = 0; i < 12; ++i)
{
sprintf(str, "%s_%d.png", "zibao", i);
CCSpriteFrame *frame = cache->spriteFrameByName(str);
animFrames->addObject(frame);
}
CCAnimation* animation = CCAnimation::animationWithFrames(animFrames, 0.2);
CCAnimate* animate = CCAnimate::actionWithAnimation(animation);
CCSprite * dazhao = CCSprite::spriteWithSpriteFrameName("zibao_0.png");
dazhao->setPosition(ccp(1024/ 2, 600 / 2));
addChild(dazhao,100);
CCCallFuncN *callback = CCCallFuncN::actionWithTarget(this, callfuncN_selector(GamingLayer::RemovedaZhaoEffect));
CCFiniteTimeAction *seq = CCSequence::actions(animate, callback, NULL);
dazhao->runAction(seq);
}
示例4: rebuildIndexInOrder
unsigned int CCSpriteBatchNode::rebuildIndexInOrder(CCSprite *pobParent, unsigned int uIndex)
{
CCMutableArray<CCNode*> *pChildren = pobParent->getChildren();
if (pChildren && pChildren->count() > 0)
{
CCSprite *pSprite;
CCMutableArray<CCNode*>::CCMutableArrayIterator iter;
for (iter = pChildren->begin(); iter != pChildren->end(); ++iter)
{
pSprite = (CCSprite*)(*iter);
if (! pSprite)
{
break;
}
if (pSprite->getZOrder() < 0)
{
uIndex = rebuildIndexInOrder(pSprite, uIndex);
}
}
}
// ignore self (batch node)
if (! pobParent->isEqual(this))
{
pobParent->setAtlasIndex(uIndex);
uIndex++;
}
if (pChildren && pChildren->count() > 0)
{
CCSprite *pSprite;
CCMutableArray<CCNode*>::CCMutableArrayIterator iter;
for (iter = pChildren->begin(); iter != pChildren->end(); ++iter)
{
pSprite = (CCSprite*)(*iter);
if (! pSprite)
{
break;
}
if (pSprite->getZOrder() >= 0)
{
uIndex = rebuildIndexInOrder(pSprite, uIndex);
}
}
}
return uIndex;
}
示例5: ccc3
CCMutableArray<StringLabel*>* TagString::parse( bool useTag )
{
string cut = "";
int start_idx = 0;
float zen_width = 0;
// 全角幅を取得
{
StringLabel* label_zen = StringLabel::init( "1", ccc3(0,0,0), baseFontSize );
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
zen_width = (int)(label_zen->getContentSize().width);
#else
zen_width = label_zen->getContentSize().width;
#endif
}
/////////////////////////////////////////////
// 変数タグの置換
start_idx = 0;
for( ;; )
{
int tag_start1 = tagStr.find( "<param=", start_idx );
if( tag_start1 == string::npos ) break;
int tag_start2 = tagStr.find( ">", tag_start1 );
string param_str = tagStr.substr( tag_start1+7, tag_start2-(tag_start1+7) );
// 変数の値取得
string value = ParamList::shared()->getValue( param_str );
if( !value.empty() )
{
// 文字列の置換
tagStr.replace( tag_start1, tag_start2-tag_start1+1, value );
start_idx = 0;
continue;
}
start_idx = tag_start2 + 1;
}
//tagStr->getStringWidth()
/////////////////////////////////////////////
// 自動改行チェック
if( autoKaigyouFlg )
{
vector< string > list = StringComparator::comparate( tagStr );
bool tag_start = false;
float total_size = 0;
string conv_str = "";
for( int i = 0; i < list.size(); i++ )
{
if (useTag)
{
if( list[i] == "<" )
{
tag_start = true;
}
if( list[i] == ">" )
{
tag_start = false;
conv_str.append( list[i] );
continue;
}
if( tag_start )
{
// 改行チェック
if( list[i] == "b" )
{
if( list[i+1] == "r" )
{
total_size = 0;
}
}
conv_str.append( list[i] );
continue;
}
}
float strw = 0;
// 半角
if( list[i].length() == 1 )
{
StringLabel* label = StringLabel::init( list[i].c_str(), ccc3(0,0,0), baseFontSize );
//.........这里部分代码省略.........
示例6: atoi
void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string, CCObject*> *dictionary, CCTexture2D *pobTexture)
{
/*
Supported Zwoptex Formats:
ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version
ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b
ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1
ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
*/
CCDictionary<std::string, CCObject*> *metadataDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("metadata"));
CCDictionary<std::string, CCObject*> *framesDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("frames"));
int format = 0;
// get the format
if(metadataDict != NULL)
{
format = atoi(valueForKey("format", metadataDict));
}
// check the format
CCAssert(format >=0 && format <= 3, "");
framesDict->begin();
std::string key = "";
CCDictionary<std::string, CCObject*> *frameDict = NULL;
while( (frameDict = (CCDictionary<std::string, CCObject*>*)framesDict->next(&key)) )
{
CCSpriteFrame *spriteFrame = m_pSpriteFrames->objectForKey(key);
if (spriteFrame)
{
continue;
}
if(format == 0)
{
float x = (float)atof(valueForKey("x", frameDict));
float y = (float)atof(valueForKey("y", frameDict));
float w = (float)atof(valueForKey("width", frameDict));
float h = (float)atof(valueForKey("height", frameDict));
float ox = (float)atof(valueForKey("offsetX", frameDict));
float oy = (float)atof(valueForKey("offsetY", frameDict));
int ow = atoi(valueForKey("originalWidth", frameDict));
int oh = atoi(valueForKey("originalHeight", frameDict));
// check ow/oh
if(!ow || !oh)
{
CCLOG("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
}
// abs ow/oh
ow = abs(ow);
oh = abs(oh);
// create frame
spriteFrame = new CCSpriteFrame();
spriteFrame->initWithTexture(pobTexture,
CCRectMake(x, y, w, h),
false,
CCPointMake(ox, oy),
CCSizeMake((float)ow, (float)oh)
);
}
else if(format == 1 || format == 2)
{
CCRect frame = CCRectFromString(valueForKey("frame", frameDict));
bool rotated = false;
// rotation
if (format == 2)
{
rotated = atoi(valueForKey("rotated", frameDict)) == 0 ? false : true;
}
CCPoint offset = CCPointFromString(valueForKey("offset", frameDict));
CCSize sourceSize = CCSizeFromString(valueForKey("sourceSize", frameDict));
// create frame
spriteFrame = new CCSpriteFrame();
spriteFrame->initWithTexture(pobTexture,
frame,
rotated,
offset,
sourceSize
);
} else
if (format == 3)
{
// get values
CCSize spriteSize = CCSizeFromString(valueForKey("spriteSize", frameDict));
CCPoint spriteOffset = CCPointFromString(valueForKey("spriteOffset", frameDict));
CCSize spriteSourceSize = CCSizeFromString(valueForKey("spriteSourceSize", frameDict));
CCRect textureRect = CCRectFromString(valueForKey("textureRect", frameDict));
bool textureRotated = atoi(valueForKey("textureRotated", frameDict)) == 0 ? false : true;
// get aliases
CCMutableArray<CCString*> *aliases = (CCMutableArray<CCString*> *) (frameDict->objectForKey(std::string("aliases")));
CCMutableArray<CCString*>::CCMutableArrayIterator iter;
CCString * frameKey = new CCString(key.c_str());
for (iter = aliases->begin(); iter != aliases->end(); ++iter)
//.........这里部分代码省略.........
示例7: startElement
void startElement(void *ctx, const char *name, const char **atts)
{
CC_UNUSED_PARAM(ctx);
CC_UNUSED_PARAM(atts);
std::string sName((char*)name);
if( sName == "dict" )
{
m_pCurDict = new CCDictionary<std::string, CCObject*>();
if(! m_pRootDict)
{
// Because it will call m_pCurDict->release() later, so retain here.
m_pRootDict = m_pCurDict;
m_pRootDict->retain();
}
m_tState = SAX_DICT;
CCSAXState preState = SAX_NONE;
if (! m_tStateStack.empty())
{
preState = m_tStateStack.top();
}
if (SAX_ARRAY == preState)
{
// add the dictionary into the array
m_pArray->addObject(m_pCurDict);
}
else if (SAX_DICT == preState)
{
// add the dictionary into the pre dictionary
CCAssert(! m_tDictStack.empty(), "The state is wrong!");
CCDictionary<std::string, CCObject*>* pPreDict = m_tDictStack.top();
pPreDict->setObject(m_pCurDict, m_sCurKey);
}
m_pCurDict->release();
// record the dict state
m_tStateStack.push(m_tState);
m_tDictStack.push(m_pCurDict);
}
else if(sName == "key")
{
m_tState = SAX_KEY;
}
else if(sName == "integer")
{
m_tState = SAX_INT;
}
else if(sName == "real")
{
m_tState = SAX_REAL;
}
else if(sName == "string")
{
m_tState = SAX_STRING;
}
else if (sName == "array")
{
m_tState = SAX_ARRAY;
m_pArray = new CCMutableArray<CCObject*>();
CCSAXState preState = m_tStateStack.empty() ? SAX_DICT : m_tStateStack.top();
if (preState == SAX_DICT)
{
m_pCurDict->setObject(m_pArray, m_sCurKey);
}
else if (preState == SAX_ARRAY)
{
CCAssert(! m_tArrayStack.empty(), "The state is worng!");
CCMutableArray<CCObject*>* pPreArray = m_tArrayStack.top();
pPreArray->addObject(m_pArray);
}
m_pArray->release();
// record the array state
m_tStateStack.push(m_tState);
m_tArrayStack.push(m_pArray);
}
else
{
m_tState = SAX_NONE;
}
}
示例8: CCRectMake
void HelloWorld::updateGame(ccTime dt)
{
CCMutableArray<CCSprite*> *projectilesToDelete =
new CCMutableArray<CCSprite*>;
CCMutableArray<CCSprite*>::CCMutableArrayIterator it, jt;
for (it = _projectiles->begin(); it != _projectiles->end(); it++)
{
CCSprite *projectile =*it;
CCRect projectileRect = CCRectMake(
projectile->getPosition().x - (projectile->getContentSize().width/2),
projectile->getPosition().y - (projectile->getContentSize().height/2),
projectile->getContentSize().width,
projectile->getContentSize().height);
CCMutableArray<CCSprite*>*targetsToDelete =new CCMutableArray<CCSprite*>;
for (jt = _targets->begin(); jt != _targets->end(); jt++)
{
CCSprite *target =*jt;
CCRect targetRect = CCRectMake(
target->getPosition().x - (target->getContentSize().width/2),
target->getPosition().y - (target->getContentSize().height/2),
target->getContentSize().width,
target->getContentSize().height);
if (CCRect::CCRectIntersectsRect(projectileRect, targetRect))
{
targetsToDelete->addObject(target);
}
}
for (jt = targetsToDelete->begin(); jt != targetsToDelete->end(); jt++)
{
CCSprite *target =*jt;
_targets->removeObject(target);
this->removeChild(target, true);
_projectilesDestroyed++;
if (_projectilesDestroyed >= 5)
{
GameOverScene *gameOverScene = GameOverScene::node();
gameOverScene->getLayer()->getLabel()->setString("You Win!");
CCDirector::sharedDirector()->replaceScene(gameOverScene);
}
}
if (targetsToDelete->count() > 0)
{
projectilesToDelete->addObject(projectile);
}
targetsToDelete->release();
}
for (it = projectilesToDelete->begin(); it != projectilesToDelete->end(); it++)
{
CCSprite* projectile =*it;
_projectiles->removeObject(projectile);
this->removeChild(projectile, true);
}
projectilesToDelete->release();
}
示例9: CCRectMake
void HelloWorld::update(float dt)
{
CCMutableArray<CCSprite*> *projectilesToDelete =
new CCMutableArray<CCSprite*>;
CCMutableArray<CCSprite*>::CCMutableArrayIterator it, jt, testt;
for (it = _projectiles->begin(); it != _projectiles->end(); it++)
{
CCSprite *projectile =*it;
CCRect projectileRect = CCRectMake(
projectile->getPosition().x - (projectile->getContentSize().width/2),
projectile->getPosition().y - (projectile->getContentSize().height/2),
projectile->getContentSize().width,
projectile->getContentSize().height);
CCMutableArray<CCSprite*>*targetsToDelete =new CCMutableArray<CCSprite*>;
//CCLOG("UPDATE2!!");
for (jt = _targets->begin(); jt != _targets->end(); jt++)
{
CCSprite *target =*jt;
CCRect targetRect = CCRectMake(
target->getPosition().x - (target->getContentSize().width/2),
target->getPosition().y - (target->getContentSize().height/2),
target->getContentSize().width,
target->getContentSize().height);
if (CCRect::CCRectIntersectsRect(projectileRect, targetRect))
{
targetsToDelete->addObject(target);
//CCLOG("HIT!!");
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("enemydeath.wav");
m_score->add_scroe(1);
m_score->update_logic(dt);
}
}
for (jt = targetsToDelete->begin(); jt != targetsToDelete->end(); jt++)
{
CCSprite *target =*jt;
_targets->removeObject(target);
this->removeChild(target, true);
_targetsKilled++;
//CCLOG("%d killed!", _targetsKilled);
if (_targetsKilled == GAMELENGTHVAL*10)
{
_targetsKilled = 0;
CCDirector::sharedDirector()->replaceScene(WinScene::scene());
}
}
if (targetsToDelete->count() >0)
{
projectilesToDelete->addObject(projectile);
}
targetsToDelete->release();
}
for (it = projectilesToDelete->begin(); it != projectilesToDelete->end(); it++)
{
CCSprite* projectile =*it;
_projectiles->removeObject(projectile);
this->removeChild(projectile, true);
}
projectilesToDelete->release();
}
示例10: CCAssert
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
SimpleAudioEngine::sharedEngine()->preloadEffect("pickup.caf");
SimpleAudioEngine::sharedEngine()->preloadEffect("hit.caf");
SimpleAudioEngine::sharedEngine()->preloadEffect("move.caf");
SimpleAudioEngine::sharedEngine()->playBackgroundMusic("TileMap.caf");
_enemies = new CCMutableArray<CCSprite *>;
_projectiles = new CCMutableArray<CCSprite *>;
_tileMap = CCTMXTiledMap::tiledMapWithTMXFile("TileMap.tmx");
_tileMap->retain();
_background = _tileMap->layerNamed("Background");
_background->retain();
_foreground = _tileMap->layerNamed("Foreground");
_foreground->retain();
_meta = _tileMap->layerNamed("Meta");
_meta->retain();
CCTMXObjectGroup *objects = _tileMap->objectGroupNamed("Objects");
CCAssert(objects != NULL, "'Objects' object group not found");
CCStringToStringDictionary *spawnPoint = objects->objectNamed("SpawnPoint");
CCAssert(spawnPoint != NULL, "SpawnPoint object not found");
int x = spawnPoint->objectForKey("x")->toInt();
int y = spawnPoint->objectForKey("y")->toInt();
this->addChild(_tileMap);
_player = CCSprite::spriteWithFile("Player.png");
_player->retain();
_player->setPosition(ccp (x, y));
this->addChild(_player);
this->setViewpointCenter(_player->getPosition());
CCMutableArray<CCStringToStringDictionary*> *allObjects = objects->getObjects();
CCMutableArray<CCStringToStringDictionary*>::CCMutableArrayIterator it;
for (it = allObjects->begin(); it != allObjects->end(); ++it)
{
if ((*it)->objectForKey(std::string("Enemy")) != NULL)
{
int x = (*it)->objectForKey("x")->toInt();
int y = (*it)->objectForKey("y")->toInt();
this->addEnemyAt(x, y);
}
}
this->setIsTouchEnabled(true);
_numCollected = 0;
_mode = 0;
this->schedule(schedule_selector(HelloWorld::testCollisions));
return true;
}
示例11: CCRectMake
void HelloWorld::testCollisions(ccTime dt)
{
CCMutableArray<CCSprite*> *projectilesToDelete = new CCMutableArray<CCSprite*>;
CCMutableArray<CCSprite *>::CCMutableArrayIterator it, jt;
// iterate through projectiles
for (it = _projectiles->begin(); it != _projectiles->end(); it++) {
CCSprite *projectile = *it;
CCRect projectileRect = CCRectMake(projectile->getPosition().x - (projectile->getContentSize().width/2),
projectile->getPosition().y - (projectile->getContentSize().height/2),
projectile->getContentSize().width,
projectile->getContentSize().height);
CCMutableArray<CCSprite*> *targetsToDelete = new CCMutableArray<CCSprite*>;
// iterate through enemies, see if any intersect with current projectile
for (jt = _enemies->begin(); jt != _enemies->end(); jt++)
{
CCSprite *target = *jt;
CCRect targetRect = CCRectMake(
target->getPosition().x - (target->getContentSize().width/2),
target->getPosition().y - (target->getContentSize().height/2),
target->getContentSize().width,
target->getContentSize().height);
if (CCRect::CCRectIntersectsRect(projectileRect, targetRect)) {
targetsToDelete->addObject(target);
}
}
// delete all hit enemies
for (jt = targetsToDelete->begin(); jt != targetsToDelete->end(); jt++)
{
_enemies->removeObject(*jt);
this->removeChild((*jt), true);
}
if (targetsToDelete->count() > 0)
{
projectilesToDelete->addObject(projectile);
}
targetsToDelete->release();
}
// remove all the projectiles that hit.
for (it = projectilesToDelete->begin(); it != projectilesToDelete->end(); it++) {
CCSprite *projectile = *it;
_projectiles->removeObject(projectile, true);
this->removeChild(projectile, true);
}
for (jt = _enemies->begin(); jt != _enemies->end(); jt++)
{
CCSprite *target = *jt;
CCRect targetRect = CCRectMake(
target->getPosition().x - (target->getContentSize().width/2),
target->getPosition().y - (target->getContentSize().height/2),
target->getContentSize().width,
target->getContentSize().height);
if (CCRect::CCRectContainsPoint(targetRect, _player->getPosition())) {
this->lose();
}
}
}
示例12: CCAssert
bool CCTMXTiledMap::initWithTMXFile(const char *tmxFile)
{
CCAssert(tmxFile != NULL && strlen(tmxFile)>0, "TMXTiledMap: tmx file should not bi nil");
setContentSize(CCSizeZero);
CCTMXMapInfo *mapInfo = CCTMXMapInfo::formatWithTMXFile(tmxFile);
if (! mapInfo)
{
return false;
}
CCAssert( mapInfo->getTilesets()->count() != 0, "TMXTiledMap: Map not found. Please check the filename.");
m_tMapSize = mapInfo->getMapSize();
m_tTileSize = mapInfo->getTileSize();
m_nMapOrientation = mapInfo->getOrientation();
setObjectGroups(mapInfo->getObjectGroups());
setProperties(mapInfo->getProperties());
CC_SAFE_RELEASE(m_pTileProperties);
m_pTileProperties = mapInfo->getTileProperties();
CC_SAFE_RETAIN(m_pTileProperties);
int idx = 0;
CCMutableArray<CCTMXLayerInfo*>* layers = mapInfo->getLayers();
if (layers && layers->count()>0)
{
if (NULL == m_pTMXLayers)
{
m_pTMXLayers = new CCDictionary<std::string, CCTMXLayer*>();
CCAssert(m_pTMXLayers, "Allocate memory failed!");
}
CCTMXLayerInfo *layerInfo = NULL;
CCMutableArray<CCTMXLayerInfo*>::CCMutableArrayIterator it;
for (it = layers->begin(); it != layers->end(); ++it)
{
layerInfo = *it;
if (layerInfo && layerInfo->m_bVisible)
{
CCTMXLayer *child = parseLayer(layerInfo, mapInfo);
addChild((CCNode*)child, idx, idx);
// record the CCTMXLayer object by it's name
std::string layerName = child->getLayerName();
m_pTMXLayers->setObject(child, layerName);
// update content size with the max size
const CCSize& childSize = child->getContentSize();
CCSize currentSize = this->getContentSize();
currentSize.width = MAX( currentSize.width, childSize.width );
currentSize.height = MAX( currentSize.height, childSize.height );
this->setContentSize(currentSize);
idx++;
}
}
}
return true;
}
示例13: CCAssert
void GB2ShapeCache::addShapesWithFile(const std::string &plist) {
const char *fullName = CCFileUtils::fullPathFromRelativePath(plist.c_str());
ObjectDict *dict = CCFileUtils::dictionaryWithContentsOfFile(fullName);
CCAssert(dict != NULL, "Shape-file not found"); // not triggered - cocos2dx delivers empty dict if non was found
CCAssert(dict->count() != 0, "plist file empty or not existing");
ObjectDict *metadataDict = (ObjectDict *)dict->objectForKey("metadata");
int format = static_cast<CCString *>(metadataDict->objectForKey("format"))->toInt();
ptmRatio = static_cast<CCString *>(metadataDict->objectForKey("ptm_ratio"))->toFloat();
CCAssert(format == 1, "Format not supported");
ObjectDict *bodyDict = (ObjectDict *)dict->objectForKey("bodies");
b2Vec2 vertices[b2_maxPolygonVertices];
ObjectDict::CCObjectMapIter iter;
bodyDict->begin();
std::string bodyName;
ObjectDict *bodyData;
while ((bodyData = (ObjectDict *)bodyDict->next(&bodyName))) {
BodyDef *bodyDef = new BodyDef();
bodyDef->anchorPoint = CCPointFromString(static_cast<CCString *>(bodyData->objectForKey("anchorpoint"))->toStdString().c_str());
CCMutableArray<ObjectDict *> *fixtureList = (CCMutableArray<ObjectDict *> *)(bodyData->objectForKey("fixtures"));
FixtureDef **nextFixtureDef = &(bodyDef->fixtures);
CCMutableArray<ObjectDict *>::CCMutableArrayIterator iter;
for (iter = fixtureList->begin(); iter != fixtureList->end(); ++iter) {
b2FixtureDef basicData;
ObjectDict *fixtureData = *iter;
basicData.filter.categoryBits = static_cast<CCString *>(fixtureData->objectForKey("filter_categoryBits"))->toInt();
basicData.filter.maskBits = static_cast<CCString *>(fixtureData->objectForKey("filter_maskBits"))->toInt();
basicData.filter.groupIndex = static_cast<CCString *>(fixtureData->objectForKey("filter_groupIndex"))->toInt();
basicData.friction = static_cast<CCString *>(fixtureData->objectForKey("friction"))->toFloat();
basicData.density = static_cast<CCString *>(fixtureData->objectForKey("density"))->toFloat();
basicData.restitution = static_cast<CCString *>(fixtureData->objectForKey("restitution"))->toFloat();
basicData.isSensor = (bool)static_cast<CCString *>(fixtureData->objectForKey("isSensor"))->toInt();
CCString *cb = static_cast<CCString *>(fixtureData->objectForKey("userdataCbValue"));
int callbackData = 0;
if (cb)
callbackData = cb->toInt();
std::string fixtureType = static_cast<CCString *>(fixtureData->objectForKey("fixture_type"))->toStdString();
if (fixtureType == "POLYGON") {
CCMutableArray<ObjectDict *> *polygonsArray = (CCMutableArray<ObjectDict *> *)(fixtureData->objectForKey("polygons"));
CCMutableArray<ObjectDict *>::CCMutableArrayIterator iter;
for (iter = polygonsArray->begin(); iter != polygonsArray->end(); ++iter) {
FixtureDef *fix = new FixtureDef();
fix->fixture = basicData; // copy basic data
fix->callbackData = callbackData;
b2PolygonShape *polyshape = new b2PolygonShape();
int vindex = 0;
CCMutableArray<CCString *> *polygonArray = (CCMutableArray<CCString *> *)(*iter);
assert(polygonArray->count() <= b2_maxPolygonVertices);
CCMutableArray<CCString *>::CCMutableArrayIterator piter;
for (piter = polygonArray->begin(); piter != polygonArray->end(); ++piter) {
CCPoint offset = CCPointFromString((*piter)->toStdString().c_str());
vertices[vindex].x = (offset.x / ptmRatio) ;
vertices[vindex].y = (offset.y / ptmRatio) ;
vindex++;
}
polyshape->Set(vertices, vindex);
fix->fixture.shape = polyshape;
// create a list
*nextFixtureDef = fix;
nextFixtureDef = &(fix->next);
}
} else if (fixtureType == "CIRCLE") {
FixtureDef *fix = new FixtureDef();
fix->fixture = basicData; // copy basic data
fix->callbackData = callbackData;
ObjectDict *circleData = (ObjectDict *)fixtureData->objectForKey("circle");
b2CircleShape *circleShape = new b2CircleShape();
circleShape->m_radius = static_cast<CCString *>(circleData->objectForKey("radius"))->toFloat() / ptmRatio;
CCPoint p = CCPointFromString(static_cast<CCString *>(circleData->objectForKey("position"))->toStdString().c_str());
circleShape->m_p = b2Vec2(p.x / ptmRatio, p.y / ptmRatio);
fix->fixture.shape = circleShape;
// create a list
*nextFixtureDef = fix;
nextFixtureDef = &(fix->next);
//.........这里部分代码省略.........
示例14: CCAssert
bool Soko::InitialiseLevel(char *LevelName)
{
mLevel = 0;
mGameRunning = true;
// Neat way to remove the label when we restart
mpLevelCompleteLabel->stopAllActions();
if (mpLevelCompleteLabel->getOpacity() != 0)
mpLevelCompleteLabel->runAction(CCFadeOut::actionWithDuration(0.5));
// Load in tilemap
this->setTileMap( CCTMXTiledMap::tiledMapWithTMXFile(LevelName) );
this->getTileMap()->retain();
this->getTileMap()->setScale(0.40);
this->getTileMap()->setPosition(ccp(128+32,128));
this->addChild(this->getTileMap());
// Now place the boxes - they are stored in the map but as Objects,
// rather than tiles, since I know they will move
CCTMXObjectGroup *pMobiles = this->getTileMap()->objectGroupNamed("Mobiles");
CCAssert(pMobiles != NULL, "Error no Mobiles layer in tile map");
CCMutableArray< CCStringToStringDictionary * > *pObjs = pMobiles->getObjects();
for( CCMutableArray< CCStringToStringDictionary * >::CCMutableArrayIterator it = pObjs->begin();
it != pObjs->end(); ++it)
{
CCStringToStringDictionary *pDict = *it;
if ( pDict->objectForKey("name")->toStdString().compare("Box") == 0 )
{
int BoxX = pDict->objectForKey("x")->toInt();
int BoxY = pDict->objectForKey("y")->toInt();
// Since meta layer is by pixel, rather than by tile
// Grid coord needs to be divided by 64
// TODO - Box texture should change when it is over a goal point.
// Works fine, so long as box doesn't start on a goal
CCSprite *pBoxSprite = CCSprite::spriteWithTexture(mpSpriteBatchNode->getTexture(),
CCRectMake(64,0,64,64));
// No scaling needed since it is a child of layer
pBoxSprite->setTag(1);
pBoxSprite->setPosition( ccp(BoxX+32, BoxY+32) );
this->getTileMap()->addChild(pBoxSprite);
}
}
// Position the player
mpPlayer = new Player();
mpPlayer->init(); // Should this happen automatically? It doesn't.
// TODO - Should do this in player init() fn?
mpPlayer->mpSprite = CCSprite::spriteWithTexture(mpSpriteBatchNode->getTexture(),
CCRectMake(0,0,64,64));
CCStringToStringDictionary *spawnPoint = pMobiles->objectNamed("PlayerStart");
CCAssert(spawnPoint != NULL, "PlayerStart object not found in Mobiles layer");
int PX = spawnPoint->objectForKey("x")->toInt();
int PY = spawnPoint->objectForKey("y")->toInt();
// I don't see why I can't just set player position - needs to be mpSprite position
mpPlayer->mpSprite->setPosition( ccp(PX+32, PY+32) );
this->getTileMap()->addChild(mpPlayer->mpSprite);
mpPlayer->mIsMoving = false;
return true;
}
示例15: CCRectMake
void HelloWorld::update(ccTime dt)
{
CCMutableArray<CCSprite*> *projectilesToDelete =
new CCMutableArray<CCSprite*>;
CCMutableArray<CCSprite*>::CCMutableArrayIterator it, jt;
for (it = _projectiles->begin(); it != _projectiles->end(); it++)
{
CCSprite *projectile =*it;
CCRect projectileRect = CCRectMake(
projectile->getPosition().x
- (projectile->getContentSize().width/2),
projectile->getPosition().y
- (projectile->getContentSize().height/2),
projectile->getContentSize().width,
projectile->getContentSize().height);
CCMutableArray<CCSprite*>*targetsToDelete
= new CCMutableArray<CCSprite*>;
for (jt = _targets->begin(); jt != _targets->end(); jt++)
{
CCSprite *target =*jt;
CCRect targetRect = CCRectMake(
target->getPosition().x - (target->getContentSize().width/2),
target->getPosition().y - (target->getContentSize().height/2),
target->getContentSize().width,
target->getContentSize().height);
if (CCRect::CCRectIntersectsRect(projectileRect, targetRect))
{
targetsToDelete->addObject(target);
}
}
for (jt = targetsToDelete->begin();
jt != targetsToDelete->end();
jt++)
{
CCSprite *target =*jt;
_targets->removeObject(target);
this->removeChild(target, true);
}
if (targetsToDelete->count() >0)
{
projectilesToDelete->addObject(projectile);
}
targetsToDelete->release();
}
for (it = projectilesToDelete->begin();
it != projectilesToDelete->end();
it++)
{
CCSprite* projectile =*it;
_projectiles->removeObject(projectile);
this->removeChild(projectile, true);
}
projectilesToDelete->release();
}