コード例 #1
0
ファイル: Sprite.cpp プロジェクト: sainthsu/Flakor
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);
}
コード例 #2
0
ファイル: CCSprite.cpp プロジェクト: songmiao/WagonWar
bool Sprite::initWithTexture(Texture2D *texture)
{
    CCASSERT(texture != nullptr, "Invalid texture for sprite");

    Rect rect = Rect::ZERO;
    rect.size = texture->getContentSize();

    return initWithTexture(texture, rect);
}
コード例 #3
0
ファイル: Player.cpp プロジェクト: fatdai/Net_2
Player* Player::createPlayer(Texture2D* texture){
    auto bob = new Player;
    if (bob->initWithTexture(texture)) {
        bob->autorelease();
        return bob;
    }
    CC_SAFE_RELEASE(bob);
    return nullptr;
}
コード例 #4
0
ファイル: CCSprite.cpp プロジェクト: songmiao/WagonWar
bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame)
{
    CCASSERT(spriteFrame != nullptr, "");

    bool bRet = initWithTexture(spriteFrame->getTexture(), spriteFrame->getRect());
    setSpriteFrame(spriteFrame);

    return bRet;
}
コード例 #5
0
ファイル: Monster.cpp プロジェクト: Gasbebe/cocos2d_source
Monster::Monster() :
	_listener(nullptr),
	_fixedPriority(0),
	_useNodePriority(false) {

	bool b0k = initWithTexture(nullptr, Rect::ZERO);
	if (b0k) {
		this->autorelease();
	}
}
コード例 #6
0
ファイル: Projectile.cpp プロジェクト: Cueroqu/LoireForGithub
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;
}
コード例 #7
0
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;
}
コード例 #8
0
ファイル: CCSprite.cpp プロジェクト: 253056965/cocos2d-x-lite
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;
}
コード例 #9
0
ファイル: CCLabel.cpp プロジェクト: wade0317/Calc
 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;
 }
コード例 #10
0
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++;
}
コード例 #11
0
ファイル: CCSprite.cpp プロジェクト: Ratel13/Cocos2dGame-v3.7
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;
}
コード例 #12
0
ファイル: CCSprite.cpp プロジェクト: 253056965/cocos2d-x-lite
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;
}
コード例 #13
0
void FilteredSpriteWithMulti::clearFilter()
{
    //CCLOG("FilteredSpriteWithMulti::clearFilter");
    _pFilters.clear();
    if (_pTexture)
    {
        initWithTexture(_pTexture, _rect);
    }
    else if (_pFrame)
    {
        initWithSpriteFrame(_pFrame);
    }
}
コード例 #14
0
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;
}
コード例 #15
0
ファイル: CCSprite.cpp プロジェクト: boruis/cocos2dx-lite
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;
}
コード例 #16
0
ファイル: CCSprite.cpp プロジェクト: 253056965/cocos2d-x-lite
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;
}
コード例 #17
0
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;
}
コード例 #18
0
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;
	}
}
コード例 #19
0
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;
    }
}
コード例 #20
0
ファイル: CCSprite.cpp プロジェクト: AIRIA/CreazyBomber
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;
}
コード例 #21
0
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;
    }
}
コード例 #22
0
ファイル: CCSprite.cpp プロジェクト: valentinvit/cocos2d-x
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;
}
コード例 #23
0
ファイル: CCTextureAtlas.cpp プロジェクト: issamux/WebGame
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;
	}
}
コード例 #24
0
ファイル: Sprite.cpp プロジェクト: sainthsu/Flakor
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;
}
コード例 #25
0
ファイル: CCSprite.cpp プロジェクト: boruis/cocos2dx-lite
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;
}
コード例 #26
0
ファイル: Sprite.cpp プロジェクト: sainthsu/Flakor
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;
}
コード例 #27
0
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);
}
コード例 #28
0
ファイル: CCSprite.cpp プロジェクト: boruis/cocos2dx-lite
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;
}
コード例 #29
0
ファイル: CCSpriteFrame.cpp プロジェクト: MySure/Test
bool CCSpriteFrame::initWithTexture(CCTexture2D* pobTexture, CCRect rect)
{
	CCRect rectInPixels = CC_RECT_POINTS_TO_PIXELS(rect);
	return initWithTexture(pobTexture, rectInPixels, false, CCPointZero, rectInPixels.size);
}
コード例 #30
0
/*
 * init with FileImage
 */
bool ParticleBatchNode::initWithFile(const std::string& fileImage, int capacity)
{
    Texture2D *tex = Director::getInstance()->getTextureCache()->addImage(fileImage);
    return initWithTexture(tex, capacity);
}