bool Sprite::initWithTexture(Texture2D *texture) { FKAssert(texture != nullptr, "Invalid texture for sprite"); Rect rect = RectMake(0,0,0,0); rect.size = texture->getContentSize(); return initWithTexture(texture, rect); }
bool Sprite::initWithTexture(Texture2D *texture) { CCASSERT(texture != nullptr, "Invalid texture for sprite"); Rect rect = Rect::ZERO; rect.size = texture->getContentSize(); return initWithTexture(texture, rect); }
Player* Player::createPlayer(Texture2D* texture){ auto bob = new Player; if (bob->initWithTexture(texture)) { bob->autorelease(); return bob; } CC_SAFE_RELEASE(bob); return nullptr; }
bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame) { CCASSERT(spriteFrame != nullptr, ""); bool bRet = initWithTexture(spriteFrame->getTexture(), spriteFrame->getRect()); setSpriteFrame(spriteFrame); return bRet; }
Monster::Monster() : _listener(nullptr), _fixedPriority(0), _useNodePriority(false) { bool b0k = initWithTexture(nullptr, Rect::ZERO); if (b0k) { this->autorelease(); } }
Projectile * Projectile::createWithTexture(cocos2d::Texture2D *texture) { auto ret = new Projectile(); if (ret && ret->initWithTexture(texture)) { ret->autorelease(); ret->_owner = NULL; return ret; } CC_SAFE_DELETE(ret); return ret; }
RepeatableSprite* RepeatableSprite::createWithTexture(cocos2d::Texture2D *texture, const cocos2d::Rect& rect) { auto sprite = new RepeatableSprite(); if (sprite && sprite->initWithTexture(texture, rect)) { sprite->autorelease(); sprite->initTextureRectAndPosition(); return sprite; } CC_SAFE_DELETE(sprite); return NULL; }
bool Sprite::initWithFile(const std::string &filename, const Rect& rect) { CCASSERT(!filename.empty(), "Invalid filename"); Texture2D *texture = _director->getTextureCache()->addImage(filename); if (texture) { return initWithTexture(texture, rect, false); } return false; }
static LabelLetter* createWithTexture(Texture2D *texture, const Rect& rect, bool rotated = false) { auto letter = new (std::nothrow) LabelLetter(); if (letter && letter->initWithTexture(texture, rect, rotated)) { letter->setVisible(false); letter->autorelease(); return letter; } CC_SAFE_DELETE(letter); return nullptr; }
void FilteredSpriteWithMulti::update(float delta) { if (_filterIdxCompound < 0) { return; } if (_filterIdxCompound >= _pFilters.size()) { //finish _filterIdxCompound = -1; Texture2D *texture = nullptr; texture = new Texture2D(); texture->autorelease(); Image *pNewImage = _pRenderTextureCompound->newImage(true); texture->initWithImage(pNewImage); delete pNewImage; initWithTexture(texture); _pFilterSpiteCompound->release(); _pFilterSpiteCompound = nullptr; return; } _pRenderTextureCompound->begin(); Filter* __filter = static_cast<Filter*>(_pFilters.at(_filterIdxCompound)); if (nullptr != _pFilterSpiteCompound) { _pFilterSpiteCompound->release(); _pFilterSpiteCompound = nullptr; } if (_filterIdxCompound == 0) { _pFilterSpiteCompound = _pTexture ? FilteredSpriteWithOne::createWithTexture(_pTexture) : FilteredSpriteWithOne::createWithSpriteFrame(_pFrame); } else { Texture2D *texture = nullptr; texture = new Texture2D(); texture->autorelease(); Image * pNewImage = _pRenderTextureCompound->newImage(true); texture->initWithImage(pNewImage); delete pNewImage; _pFilterSpiteCompound = FilteredSpriteWithOne::createWithTexture(texture); } _pFilterSpiteCompound->retain(); _pFilterSpiteCompound->setFilter(__filter); _pFilterSpiteCompound->setAnchorPoint(Vec2(0, 0)); _pFilterSpiteCompound->visit(); _pRenderTextureCompound->end(); _filterIdxCompound++; }
bool Sprite::initWithPolygon(const cocos2d::PolygonInfo &info) { Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(info.filename); bool res = false; if(initWithTexture(texture)); { _polyInfo = info; setContentSize(_polyInfo.rect.size/Director::getInstance()->getContentScaleFactor()); res = true; } return res; }
bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame) { CCASSERT(spriteFrame != nullptr, "spriteFrame can't be nullptr!"); if (spriteFrame == nullptr) { return false; } bool bRet = initWithTexture(spriteFrame->getTexture(), spriteFrame->getRect()); setSpriteFrame(spriteFrame); return bRet; }
void FilteredSpriteWithMulti::clearFilter() { //CCLOG("FilteredSpriteWithMulti::clearFilter"); _pFilters.clear(); if (_pTexture) { initWithTexture(_pTexture, _rect); } else if (_pFrame) { initWithSpriteFrame(_pFrame); } }
bool BlurSprite::initWithFile(const char* filename) { CCAssert(filename != NULL, "Invalid filename for sprite"); CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage(filename); if (pTexture) { CCRect rect = CCRectZero; rect.size = pTexture->getContentSize(); return initWithTexture(pTexture, rect); } return false; }
bool Sprite::initWithPolygon(const cocos2d::PolygonInfo &info) { bool ret = false; Texture2D *texture = _director->getTextureCache()->addImage(info.filename); if(texture && initWithTexture(texture)) { _polyInfo = info; setContentSize(_polyInfo.rect.size / _director->getContentScaleFactor()); ret = true; } return ret; }
bool Sprite::initWithFile(const std::string& filename) { CCASSERT(!filename.empty(), "Invalid filename for sprite"); Texture2D *texture = _director->getTextureCache()->addImage(filename); if (texture) { Rect rect = Rect::ZERO; rect.size = texture->getContentSize(); return initWithTexture(texture, rect, false); } return false; }
bool CC3DSprite::initWithFile(const char *pszFilename, const CCRect& rect) { CCAssert(pszFilename != NULL, ""); CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage(pszFilename); if (pTexture) { return initWithTexture(pTexture, rect); } // don't release here. // when load texture failed, it's better to get a "transparent" sprite then a crashed program // this->release(); return false; }
KDbool CCTextureAtlas::initWithFile ( const KDchar* szFilePath, KDuint uCapacity ) { // retained in property CCTexture2D* pTexture = CCTextureCache::sharedTextureCache ( )->addImage ( szFilePath ); if ( pTexture ) { return initWithTexture ( pTexture, uCapacity ); } else { CCLOG ( "XMCocos2D : Could not open file: %s", szFilePath ); return KD_FALSE; } }
bool TextureAtlas::initWithFile(const std::string& file, ssize_t capacity) { // retained in property Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(file); if (texture) { return initWithTexture(texture, capacity); } else { CCLOG("cocos2d: Could not open file: %s", file.c_str()); return false; } }
bool Sprite::initWithFile(const std::string &filename, const Rect& rect) { CCASSERT(filename.size()>0, "Invalid filename"); Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); if (texture) { return initWithTexture(texture, rect); } // don't release here. // when load texture failed, it's better to get a "transparent" sprite then a crashed program // this->release(); return false; }
bool TextureAtlas::initWithFile(const char * file, int capacity) { // retained in property Texture2D *texture = TextureCache::getInstance()->addImage(file); if (texture) { return initWithTexture(texture, capacity); } else { CCLOG("cocos2d: Could not open file: %s", file); return false; } }
bool CCSprite::initWithFile(const char *pszFilename) { assert(pszFilename != NULL); CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage(pszFilename); if (pTexture) { CGRect rect = CGRectZero; rect.size = pTexture->getContentSize(); return initWithTexture(pTexture, rect); } // don't release here. // when load texture failed, it's better to get a "transparent" sprite then a crashed program // this->release(); return false; }
bool CCTextureAtlas::initWithFile(const char * file, unsigned int capacity) { // retained in property CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(file); if (texture) { return initWithTexture(texture, capacity); } else { CCLOG("cocos2d: Could not open file: %s", file); delete this; return NULL; } }
bool Sprite::initWithFile(const std::string &filename, const Rect& rect) { FKAssert(filename.size()>0, "Invalid filename"); Texture2D *texture = new Texture2D(); Image* image = dynamic_cast<Image*>(ResourceManager::thisManager()->createResource(filename.c_str(),ResourceManager::IMAGE_NAME)); image->load(false); texture->initWithImage(image); if (texture) { return initWithTexture(texture, rect); } // don't release here. // when load texture failed, it's better to get a "transparent" sprite then a crashed program // this->release(); return false; }
bool Sprite::initWithFile(const std::string &filename, const Rect& rect) { CCASSERT(!filename.empty(), "Invalid filename"); if (filename.empty()) { return false; } _fileName = filename; _fileType = 0; Texture2D *texture = _director->getTextureCache()->addImage(filename); if (texture) { return initWithTexture(texture, rect); } // don't release here. // when load texture failed, it's better to get a "transparent" sprite then a crashed program // this->release(); return false; }
bool Sprite::initWithFile(const std::string& filename) { FKAssert(filename.size()>0, "Invalid filename for sprite"); Texture2D *texture = new Texture2D(); FKLOG("create image here"); Image* image = dynamic_cast<Image*>(ResourceManager::thisManager()->createResource(filename.c_str(),ResourceManager::IMAGE_NAME)); image->load(false); texture->initWithImage(image); if (texture) { Rect rect = RectZero; rect.size = texture->getContentSize(); FKLOG("Sprite size:w %f,h %f",rect.size.width,rect.size.height); return initWithTexture(texture, rect); } // don't release here. // when load texture failed, it's better to get a "transparent" sprite then a crashed program // this->release(); return false; }
bool InstantGif::init(FILE* f,const char* fileName) { m_gif_fullpath = fileName; if(GifUtils::isGifFile(f) == false) { GifUtils::closeFile(f); return false; } m_movie = GIFMovie::create(f); if(m_movie == NULL || m_movie->getGifCount() <= 0) { return false; } if(m_movie->getGifCount()>1) { scheduleUpdate(); } m_movie->setTime(0); cocos2d::Texture2D* texture = createTexture(m_movie->bitmap(),0,false); return initWithTexture(texture); }
bool Sprite::initWithFile(const std::string& filename) { if (filename.empty()) { CCLOG("Call Sprite::initWithFile with blank resource filename."); return false; } _fileName = filename; _fileType = 0; Texture2D *texture = _director->getTextureCache()->addImage(filename); if (texture) { Rect rect = Rect::ZERO; rect.size = texture->getContentSize(); return initWithTexture(texture, rect); } // don't release here. // when load texture failed, it's better to get a "transparent" sprite then a crashed program // this->release(); return false; }
bool CCSpriteFrame::initWithTexture(CCTexture2D* pobTexture, CCRect rect) { CCRect rectInPixels = CC_RECT_POINTS_TO_PIXELS(rect); return initWithTexture(pobTexture, rectInPixels, false, CCPointZero, rectInPixels.size); }
/* * init with FileImage */ bool ParticleBatchNode::initWithFile(const std::string& fileImage, int capacity) { Texture2D *tex = Director::getInstance()->getTextureCache()->addImage(fileImage); return initWithTexture(tex, capacity); }