// XXX deprecated bool MenuItem::initWithTarget(cocos2d::Object *target, SEL_MenuHandler selector ) { _target = target; CC_SAFE_RETAIN(_target); return initWithCallback( std::bind(selector,target, std::placeholders::_1) ); }
void AtlasNode::setTextureAtlas(TextureAtlas* textureAtlas) { CC_SAFE_RETAIN(textureAtlas); CC_SAFE_RELEASE(_textureAtlas); _textureAtlas = textureAtlas; }
VolatileTexture_richlabel::VolatileTexture_richlabel(CCTexture2D_richlabel* t) : m_texture(t), m_cachedImageType(kInvalid) { s_textures.push_back(this); CC_SAFE_RETAIN(m_texture); }
void MapManager::loadFarMap(int resId,int mapResRow,int mapResColumn) { if(_currentFarResId==resId) return; // if (floor(resId/1000)!=3) return; _currentFarResId=resId; if(_farMapNode) { _farMapNode->removeFromParent(); } else { _farMapNode=Node::create(); CC_SAFE_RETAIN(_farMapNode); } if (_farMapImgsMap) { _farMapImgsMap->clear(); } else { _farMapImgsMap=new std::map<std::string,bool>; } std::stringstream myStringStream; myStringStream<<"map/"<<resId; std::string mapDir=myStringStream.str(); char mapImgPath[256]={0}; float offsetX=0.0f; // float offsetY=0.0f; Sprite* spriteNode=nullptr; bool isPictureExist=false; Size contentSize; for (int row =1;row<=mapResRow;row++) { for (int column=1;column<=mapResColumn;column++) { sprintf(mapImgPath, "%s/m%d%03d.jpg",mapDir.c_str(),row,column); isPictureExist=FileUtils::getInstance()->isFileExist(mapImgPath); if (!isPictureExist) { sprintf(mapImgPath, "%s/m%d%03d.png",mapDir.c_str(),row,column); isPictureExist=FileUtils::getInstance()->isFileExist(mapImgPath); } if(isPictureExist) { spriteNode=Sprite::create(mapImgPath); spriteNode->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT); _farMapNode->addChild(spriteNode); spriteNode->setPosition(offsetX,_mapHeight); contentSize=spriteNode->getContentSize(); offsetX=offsetX+contentSize.width; (*_farMapImgsMap)[mapImgPath]=true; } else { offsetX=offsetX+512; CCLOG("far map file no exist:%s",mapImgPath); } } } }
GameLayer::GameLayer() : running(true) { timer = TimerSprite::create(); CC_SAFE_RETAIN(timer); }
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; }
void NodeGrid::setGrid(GridBase *grid) { CC_SAFE_RELEASE(_nodeGrid); CC_SAFE_RETAIN(grid); _nodeGrid = grid; }
void ArmatureAnimation::setUserObject(Ref *pUserObject) { CC_SAFE_RETAIN(pUserObject); CC_SAFE_RELEASE(_userObject); _userObject = pUserObject; }
void CCDirector::setNotificationNode(CCNode *node) { CC_SAFE_RELEASE(m_pNotificationNode); m_pNotificationNode = node; CC_SAFE_RETAIN(m_pNotificationNode); }
void CCTMXLayer::setTileSet(CCTMXTilesetInfo* var) { CC_SAFE_RETAIN(var); CC_SAFE_RELEASE(m_pTileSet); m_pTileSet = var; }
void CCTextureAtlas::setTexture(CCTexture2D * var) { CC_SAFE_RETAIN(var); CC_SAFE_RELEASE(m_pTexture); m_pTexture = var; }
void Hero::setTiledMap(CCTMXTiledMap* map) { CC_SAFE_RETAIN(map); CC_SAFE_RELEASE(m_map); this->m_map = map; }
void CCMenuItemToggle::setSubItems(CCArray* var) { CC_SAFE_RETAIN(var); CC_SAFE_RELEASE(m_pSubItems); m_pSubItems = var; }
// XXX: deprecated bool MenuItemToggle::initWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, va_list args) { _target = target; CC_SAFE_RETAIN(_target); return initWithCallback(std::bind( selector, target, std::placeholders::_1), item, args); }
void CCTMXTiledMap::setObjectGroups(CCMutableArray<CCTMXObjectGroup*>* var) { CC_SAFE_RETAIN(var); CC_SAFE_RELEASE(m_pObjectGroups); m_pObjectGroups = var; }
void Situation::raiseSituation(Situation* situation) { this->subSituation = situation; CC_SAFE_RETAIN(this->subSituation); }
void CCTMXTiledMap::setProperties(CCStringToStringDictionary* var) { CC_SAFE_RETAIN(var); CC_SAFE_RELEASE(m_pProperties); m_pProperties = var; }
void Node::setUserObject(Ref* userObject) { CC_SAFE_RETAIN(userObject); CC_SAFE_RELEASE(_userObject); _userObject = userObject; }
bool MainMenuLayer::init() { if (!Layer::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); CC_SAFE_RELEASE_NULL(_pPauseAndGold); CC_SAFE_RELEASE_NULL(_pRestartButton); CC_SAFE_RELEASE_NULL(_pGoldText); CC_SAFE_RELEASE_NULL(_pGoldImage); CC_SAFE_RELEASE_NULL(_pPauseButton); _pPauseAndGold = cocostudio::GUIReader::getInstance()->widgetFromJsonFile("HUD/HUD.json"); this->addChild(_pPauseAndGold, 100); CC_SAFE_RETAIN(_pPauseAndGold); _pGoldText = dynamic_cast<ui::TextAtlas *>(_pPauseAndGold->getChildByName("gold")); CC_SAFE_RETAIN(_pGoldText); _pGoldText->setString("0"); _pGoldText->setPosition(Vec2(origin.x + visibleSize.width - _pGoldText->getContentSize().width, origin.y + visibleSize.height - _pGoldText->getContentSize().height)); _pGoldImage = dynamic_cast<ui::ImageView *>(_pPauseAndGold->getChildByName("Image_3")); _pGoldImage->setPosition(Vec2(_pGoldText->getPositionX() - _pGoldImage->getContentSize().width, _pGoldText->getPositionY())); CC_SAFE_RETAIN(_pGoldImage); _pPauseButton = dynamic_cast<cocos2d::ui::Button *>(_pPauseAndGold->getChildByName("Button_1")); CC_SAFE_RETAIN(_pPauseButton); _pPauseButton->addTouchEventListener( [&](Ref * sender,cocos2d::ui::Widget::TouchEventType type) { static bool bIsPaused = false; if (type == cocos2d::ui::Widget::TouchEventType::ENDED) { if (bIsPaused) { bIsPaused = false; Director::getInstance()->resume(); } else { Director::getInstance()->pause(); bIsPaused = true; } }//if_type }//lambdy ); _pPauseButton->setPosition(Vec2(origin.x + _pPauseButton->getContentSize().width / 2, origin.y + visibleSize.height - _pPauseButton->getContentSize().height / 2)); _pPauseButton->setVisible(true); auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(MainMenuLayer::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width / 2, origin.y + closeItem->getContentSize().height / 2)); auto menu = Menu::create(closeItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 100); auto label = Label::createWithTTF("Game Parkour", "fonts/Marker Felt.ttf", 24); label->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - label->getContentSize().height)); this->addChild(label,100); //this->scheduleUpdate(); _pGoldChanged = EventListenerCustom::create(RegitsteredEvents::GOLD_CHANGED, CC_CALLBACK_1(MainMenuLayer::ChangeGold, this)); Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(_pGoldChanged, this); CC_SAFE_RETAIN(_pGoldChanged); _pRestartButton = cocostudio::GUIReader::getInstance()->widgetFromJsonFile("Menu/Menu.json"); this->addChild(_pRestartButton, 10); auto restart_btn = dynamic_cast<cocos2d::ui::Button *>(_pRestartButton->getChildByName("restart")); restart_btn->addTouchEventListener([&](Ref* sender, cocos2d::ui::Widget::TouchEventType type) { if (type == cocos2d::ui::Widget::TouchEventType::ENDED) { Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(RegitsteredEvents::GAME_RESTART); } }); _pRestartButton->setVisible(false); CC_SAFE_RETAIN(_pRestartButton); return true; }
void RenderState::setStateBlock(RenderState::StateBlock* state) { CC_SAFE_RETAIN(state); CC_SAFE_RELEASE(_state); _state = state; }
void NodeGrid::setTarget(Node* target) { CC_SAFE_RELEASE(_gridTarget); CC_SAFE_RETAIN(target); _gridTarget = target; }
void ActionObject::play(CallFunc* func) { this->play(); this->_CallBack = func; CC_SAFE_RETAIN(_CallBack); }
void EventDispatcher::removeEventListener(EventListener* listener) { if (listener == nullptr) return; // just return if listener is in _toRemovedListeners to avoid remove listeners more than once if (std::find(_toRemovedListeners.begin(), _toRemovedListeners.end(), listener) != _toRemovedListeners.end()) return; bool isFound = false; auto removeListenerInVector = [&](std::vector<EventListener*>* listeners){ if (listeners == nullptr) return; for (auto iter = listeners->begin(); iter != listeners->end(); ++iter) { auto l = *iter; if (l == listener) { CC_SAFE_RETAIN(l); l->setRegistered(false); if (l->getAssociatedNode() != nullptr) { dissociateNodeAndEventListener(l->getAssociatedNode(), l); l->setAssociatedNode(nullptr); // nullptr out the node pointer so we don't have any dangling pointers to destroyed nodes. } if (_inDispatch == 0) { iter = listeners->erase(iter); releaseListener(l); } else { _toRemovedListeners.push_back(l); } isFound = true; break; } } }; for (auto iter = _listenerMap.begin(); iter != _listenerMap.end();) { auto listeners = iter->second; auto fixedPriorityListeners = listeners->getFixedPriorityListeners(); auto sceneGraphPriorityListeners = listeners->getSceneGraphPriorityListeners(); removeListenerInVector(sceneGraphPriorityListeners); if (isFound) { // fixed #4160: Dirty flag need to be updated after listeners were removed. setDirty(listener->getListenerID(), DirtyFlag::SCENE_GRAPH_PRIORITY); } else { removeListenerInVector(fixedPriorityListeners); if (isFound) { setDirty(listener->getListenerID(), DirtyFlag::FIXED_PRIORITY); } } #if CC_NODE_DEBUG_VERIFY_EVENT_LISTENERS CCASSERT(_inDispatch != 0 || !sceneGraphPriorityListeners || std::count(sceneGraphPriorityListeners->begin(), sceneGraphPriorityListeners->end(), listener) == 0, "Listener should be in no lists after this is done if we're not currently in dispatch mode."); CCASSERT(_inDispatch != 0 || !fixedPriorityListeners || std::count(fixedPriorityListeners->begin(), fixedPriorityListeners->end(), listener) == 0, "Listener should be in no lists after this is done if we're not currently in dispatch mode."); #endif if (iter->second->empty()) { _priorityDirtyFlagMap.erase(listener->getListenerID()); auto list = iter->second; iter = _listenerMap.erase(iter); CC_SAFE_DELETE(list); } else { ++iter; } if (isFound) break; } if (isFound) { releaseListener(listener); } else { for(auto iter = _toAddedListeners.begin(); iter != _toAddedListeners.end(); ++iter) { if (*iter == listener) { listener->setRegistered(false); releaseListener(listener); _toAddedListeners.erase(iter); break; } } } }
bool GAFAsset::initWithImageData(const std::string& jsonPath) { if (!s3eFileCheckExists(jsonPath.c_str())) { GAFLOGERROR("CAN NOT create GAFAsset : %s does not exists", jsonPath.c_str()); return false; } GAFData aConfigData; //std::string fp = CCFileUtils::sharedFileUtils()->fullPathForFilename(jsonPath.c_str()); std::string fp = jsonPath; s3eFile * file = s3eFileOpen (fp.c_str(), "rb"); if (!file) { GAFLOGERROR("CAN NOT create GAFAsset : can not open %s.", fp.c_str()); return false; } aConfigData.setSize(s3eFileGetSize(file)); aConfigData.setBytes(new unsigned char[aConfigData.size()]); s3eFileRead(aConfigData.bytes(), aConfigData.size(), 1, file); s3eFileClose(file); aConfigData.setDeleteData(true); if (!aConfigData.bytes()) { GAFLOGERROR("Can not get data from json file : %s", jsonPath.c_str()); return NULL; } if (!aConfigData.bytes()) { GAFLOGWARN("can not init GAFAsset - invalid anImageData"); return false; } CCDictionary* configDictionary = CCJSONConverter::sharedConverter()->dictionaryFrom( (const char *)aConfigData.bytes()); CCString *versionNode = (CCString*)configDictionary->objectForKey(kVersionKey); if (!isAssetVersionPlayable(versionNode->getCString())) { return false; } CCArray *animationConfigFrames = (CCArray *)configDictionary->objectForKey(kAnimationConfigFramesKey); CCArray *interactionObjectNodes = (CCArray *)configDictionary->objectForKey(kInteractionObjectsKey); CCArray *standObjectsNodes = (CCArray *)configDictionary->objectForKey(kStandObjectsKey); CCArray *textureAtlasNode = (CCArray *)configDictionary->objectForKey(kTextureAtlasKey); CCArray *animationSequences = (CCArray *)configDictionary->objectForKey(kAnimationSequencesKey); CCDictionary *objectNodes = (CCDictionary *)configDictionary->objectForKey(kAnimationObjectsKey); CCDictionary *masksNodes = (CCDictionary *)configDictionary->objectForKey(kAnimationMasksKey); CCDictionary *namedPartsNodes = (CCDictionary *)configDictionary->objectForKey(kAnimationNamedPartsKey); if (!animationConfigFrames || !textureAtlasNode|| !objectNodes) { GAFLOGERROR("Error while creating GAFAsset. Required subnodes in dictionary are missing."); return false; } CC_SAFE_RELEASE(_textureAtlas); if (!textureAtlasNode->count()) { return false; } CCDictionary * atlasDictionary = (CCDictionary *)textureAtlasNode->objectAtIndex(0); float atlasScale = atlasScaleFromAtlasConfig(atlasDictionary); for (int i = 1; i < textureAtlasNode->count(); ++i) { CCDictionary * a = (CCDictionary *)textureAtlasNode->objectAtIndex(i); float as = atlasScaleFromAtlasConfig(a); if ( fabs(atlasScale - _currentDeviceScale) > fabs(as - _currentDeviceScale)) { atlasDictionary = a; atlasScale = as; } } _usedAtlasContentScaleFactor = atlasScale; CCArray * atlasesInfo = (CCArray *)atlasDictionary->objectForKey(kAtlasInfoKey); if (!atlasesInfo) { GAFLOGERROR("Error while creating GAFAsset.atlasesInfo subnode is missing in atlasDictionary."); return false; } _textureAtlas = GAFTextureAtlas::create(fp.c_str(), atlasDictionary); if (!_textureAtlas) { GAFLOGERROR("Failed to initialize GAFAsset. GAFTextureAtlas could not be created."); return false; } CC_SAFE_RETAIN(_textureAtlas); if (_objects != objectNodes) { CC_SAFE_RELEASE(_objects); _objects = objectNodes; CC_SAFE_RETAIN(_objects); } if (_masks != masksNodes) { CC_SAFE_RELEASE(_masks); _masks = masksNodes; CC_SAFE_RETAIN(_masks); } if (_namedParts != namedPartsNodes) { CC_SAFE_RELEASE(_namedParts); _namedParts = namedPartsNodes; CC_SAFE_RETAIN(_namedParts); } if (interactionObjectNodes) { CC_SAFE_RELEASE(_interactionObjects); _interactionObjects = CCArray::create(); CC_SAFE_RETAIN(_interactionObjects); for (unsigned int i = 0; i < interactionObjectNodes->count(); ++i) { CCDictionary * dict = (CCDictionary*)interactionObjectNodes->objectAtIndex(i); GAFInteractionObject * interObject = GAFInteractionObject::create(dict); if (interObject) { _interactionObjects->addObject(interObject); } } } if (standObjectsNodes) { CC_SAFE_RELEASE(_standObjects); _standObjects = CCArray::create(); CC_SAFE_RETAIN(_standObjects); for (unsigned int i = 0; i < standObjectsNodes->count(); ++i) { CCDictionary * dict = (CCDictionary*)standObjectsNodes->objectAtIndex(i); GAFActionObject * interObject = GAFActionObject::create(dict); if (interObject) { _standObjects->addObject(interObject); } } } loadFramesFromConfigDictionary(configDictionary); if (animationSequences) { loadAnimationSequences(animationSequences); } configDictionary->removeAllObjects(); return true; }
bool CCScale9Sprite::updateWithBatchNode(CCSpriteBatchNode* batchnode, CCRect rect, bool rotated, CCRect capInsets) { GLubyte opacity = getOpacity(); ccColor3B color = getColor(); // Release old sprites this->removeAllChildrenWithCleanup(true); CC_SAFE_RELEASE(this->_centre); CC_SAFE_RELEASE(this->_top); CC_SAFE_RELEASE(this->_topLeft); CC_SAFE_RELEASE(this->_topRight); CC_SAFE_RELEASE(this->_left); CC_SAFE_RELEASE(this->_right); CC_SAFE_RELEASE(this->_bottomLeft); CC_SAFE_RELEASE(this->_bottom); CC_SAFE_RELEASE(this->_bottomRight); if(this->_scale9Image != batchnode) { CC_SAFE_RELEASE(this->_scale9Image); _scale9Image = batchnode; CC_SAFE_RETAIN(_scale9Image); } _scale9Image->removeAllChildrenWithCleanup(true); m_capInsets = capInsets; // If there is no given rect if ( rect.equals(CCRectZero) ) { // Get the texture size as original CCSize textureSize = _scale9Image->getTextureAtlas()->getTexture()->getContentSize(); rect = CCRectMake(0, 0, textureSize.width, textureSize.height); } // Set the given rect's size as original size m_spriteRect = rect; m_originalSize = rect.size; m_preferredSize = m_originalSize; m_capInsetsInternal = capInsets; float w = rect.size.width; float h = rect.size.height; // If there is no specified center region if ( m_capInsetsInternal.equals(CCRectZero) ) { // CCLog("... cap insets not specified : using default cap insets ..."); m_capInsetsInternal = CCRectMake(w/3, h/3, w/3, h/3); } float left_w = m_capInsetsInternal.origin.x; float center_w = m_capInsetsInternal.size.width; float right_w = rect.size.width - (left_w + center_w); float top_h = m_capInsetsInternal.origin.y; float center_h = m_capInsetsInternal.size.height; float bottom_h = rect.size.height - (top_h + center_h); // calculate rects // ... top row float x = 0.0; float y = 0.0; // top left CCRect lefttopbounds = CCRectMake(x, y, left_w, top_h); // top center TRANSLATE_X(x, y, left_w); CCRect centertopbounds = CCRectMake(x, y, center_w, top_h); // top right TRANSLATE_X(x, y, center_w); CCRect righttopbounds = CCRectMake(x, y, right_w, top_h); // ... center row x = 0.0; y = 0.0; TRANSLATE_Y(x, y, top_h); // center left CCRect leftcenterbounds = CCRectMake(x, y, left_w, center_h); // center center TRANSLATE_X(x, y, left_w); CCRect centerbounds = CCRectMake(x, y, center_w, center_h); // center right TRANSLATE_X(x, y, center_w); CCRect rightcenterbounds = CCRectMake(x, y, right_w, center_h); // ... bottom row x = 0.0; y = 0.0; TRANSLATE_Y(x, y, top_h); TRANSLATE_Y(x, y, center_h); // bottom left CCRect leftbottombounds = CCRectMake(x, y, left_w, bottom_h); // bottom center TRANSLATE_X(x, y, left_w); CCRect centerbottombounds = CCRectMake(x, y, center_w, bottom_h); // bottom right TRANSLATE_X(x, y, center_w); CCRect rightbottombounds = CCRectMake(x, y, right_w, bottom_h); if (!rotated) { // CCLog("!rotated"); CCAffineTransform t = CCAffineTransformMakeIdentity(); t = CCAffineTransformTranslate(t, rect.origin.x, rect.origin.y); centerbounds = CCRectApplyAffineTransform(centerbounds, t); rightbottombounds = CCRectApplyAffineTransform(rightbottombounds, t); leftbottombounds = CCRectApplyAffineTransform(leftbottombounds, t); righttopbounds = CCRectApplyAffineTransform(righttopbounds, t); lefttopbounds = CCRectApplyAffineTransform(lefttopbounds, t); rightcenterbounds = CCRectApplyAffineTransform(rightcenterbounds, t); leftcenterbounds = CCRectApplyAffineTransform(leftcenterbounds, t); centerbottombounds = CCRectApplyAffineTransform(centerbottombounds, t); centertopbounds = CCRectApplyAffineTransform(centertopbounds, t); // Centre _centre = new CCSprite(); _centre->initWithTexture(_scale9Image->getTexture(), centerbounds); _scale9Image->addChild(_centre, 0, pCentre); // Top _top = new CCSprite(); _top->initWithTexture(_scale9Image->getTexture(), centertopbounds); _scale9Image->addChild(_top, 1, pTop); // Bottom _bottom = new CCSprite(); _bottom->initWithTexture(_scale9Image->getTexture(), centerbottombounds); _scale9Image->addChild(_bottom, 1, pBottom); // Left _left = new CCSprite(); _left->initWithTexture(_scale9Image->getTexture(), leftcenterbounds); _scale9Image->addChild(_left, 1, pLeft); // Right _right = new CCSprite(); _right->initWithTexture(_scale9Image->getTexture(), rightcenterbounds); _scale9Image->addChild(_right, 1, pRight); // Top left _topLeft = new CCSprite(); _topLeft->initWithTexture(_scale9Image->getTexture(), lefttopbounds); _scale9Image->addChild(_topLeft, 2, pTopLeft); // Top right _topRight = new CCSprite(); _topRight->initWithTexture(_scale9Image->getTexture(), righttopbounds); _scale9Image->addChild(_topRight, 2, pTopRight); // Bottom left _bottomLeft = new CCSprite(); _bottomLeft->initWithTexture(_scale9Image->getTexture(), leftbottombounds); _scale9Image->addChild(_bottomLeft, 2, pBottomLeft); // Bottom right _bottomRight = new CCSprite(); _bottomRight->initWithTexture(_scale9Image->getTexture(), rightbottombounds); _scale9Image->addChild(_bottomRight, 2, pBottomRight); } else { // set up transformation of coordinates // to handle the case where the sprite is stored rotated // in the spritesheet // CCLog("rotated"); m_bSpriteFrameRotated = true; CCAffineTransform t = CCAffineTransformMakeIdentity(); CCRect rotatedcenterbounds = centerbounds; CCRect rotatedrightbottombounds = rightbottombounds; CCRect rotatedleftbottombounds = leftbottombounds; CCRect rotatedrighttopbounds = righttopbounds; CCRect rotatedlefttopbounds = lefttopbounds; CCRect rotatedrightcenterbounds = rightcenterbounds; CCRect rotatedleftcenterbounds = leftcenterbounds; CCRect rotatedcenterbottombounds = centerbottombounds; CCRect rotatedcentertopbounds = centertopbounds; t = CCAffineTransformTranslate(t, rect.size.height+rect.origin.x, rect.origin.y); t = CCAffineTransformRotate(t, 1.57079633f); centerbounds = CCRectApplyAffineTransform(centerbounds, t); rightbottombounds = CCRectApplyAffineTransform(rightbottombounds, t); leftbottombounds = CCRectApplyAffineTransform(leftbottombounds, t); righttopbounds = CCRectApplyAffineTransform(righttopbounds, t); lefttopbounds = CCRectApplyAffineTransform(lefttopbounds, t); rightcenterbounds = CCRectApplyAffineTransform(rightcenterbounds, t); leftcenterbounds = CCRectApplyAffineTransform(leftcenterbounds, t); centerbottombounds = CCRectApplyAffineTransform(centerbottombounds, t); centertopbounds = CCRectApplyAffineTransform(centertopbounds, t); rotatedcenterbounds.origin = centerbounds.origin; rotatedrightbottombounds.origin = rightbottombounds.origin; rotatedleftbottombounds.origin = leftbottombounds.origin; rotatedrighttopbounds.origin = righttopbounds.origin; rotatedlefttopbounds.origin = lefttopbounds.origin; rotatedrightcenterbounds.origin = rightcenterbounds.origin; rotatedleftcenterbounds.origin = leftcenterbounds.origin; rotatedcenterbottombounds.origin = centerbottombounds.origin; rotatedcentertopbounds.origin = centertopbounds.origin; // Centre _centre = new CCSprite(); _centre->initWithTexture(_scale9Image->getTexture(), rotatedcenterbounds, true); _scale9Image->addChild(_centre, 0, pCentre); // Top _top = new CCSprite(); _top->initWithTexture(_scale9Image->getTexture(), rotatedcentertopbounds, true); _scale9Image->addChild(_top, 1, pTop); // Bottom _bottom = new CCSprite(); _bottom->initWithTexture(_scale9Image->getTexture(), rotatedcenterbottombounds, true); _scale9Image->addChild(_bottom, 1, pBottom); // Left _left = new CCSprite(); _left->initWithTexture(_scale9Image->getTexture(), rotatedleftcenterbounds, true); _scale9Image->addChild(_left, 1, pLeft); // Right _right = new CCSprite(); _right->initWithTexture(_scale9Image->getTexture(), rotatedrightcenterbounds, true); _scale9Image->addChild(_right, 1, pRight); // Top left _topLeft = new CCSprite(); _topLeft->initWithTexture(_scale9Image->getTexture(), rotatedlefttopbounds, true); _scale9Image->addChild(_topLeft, 2, pTopLeft); // Top right _topRight = new CCSprite(); _topRight->initWithTexture(_scale9Image->getTexture(), rotatedrighttopbounds, true); _scale9Image->addChild(_topRight, 2, pTopRight); // Bottom left _bottomLeft = new CCSprite(); _bottomLeft->initWithTexture(_scale9Image->getTexture(), rotatedleftbottombounds, true); _scale9Image->addChild(_bottomLeft, 2, pBottomLeft); // Bottom right _bottomRight = new CCSprite(); _bottomRight->initWithTexture(_scale9Image->getTexture(), rotatedrightbottombounds, true); _scale9Image->addChild(_bottomRight, 2, pBottomRight); } this->setContentSize(rect.size); this->addChild(_scale9Image); if (m_bSpritesGenerated) { // Restore color and opacity this->setOpacity(opacity); this->setColor(color); } m_bSpritesGenerated = true; return true; }
ColliderBody::ColliderBody(ContourData *contourData) : _contourData(contourData) { CC_SAFE_RETAIN(_contourData); }
void TextureAtlas::setTexture(Texture2D * var) { CC_SAFE_RETAIN(var); CC_SAFE_RELEASE(_texture); _texture = var; }
void ClippingNode::setStencil(Node *stencil) { CC_SAFE_RELEASE(_stencil); _stencil = stencil; CC_SAFE_RETAIN(_stencil); }
void Cocos2dxAtlasNode::setTextureAtlas(TextureAtlas* var) { CC_SAFE_RETAIN(var); CC_SAFE_RELEASE(m_pTextureAtlas); m_pTextureAtlas = var; }
// XXX: deprecated bool MenuItemImage::initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Object* target, SEL_MenuHandler selector) { _target = target; CC_SAFE_RETAIN(_target); return initWithNormalImage(normalImage, selectedImage, disabledImage, std::bind(selector,target, std::placeholders::_1) ); }