Sprite3DMaterial* Sprite3DMaterial::createWithFilename(const std::string& path)
{
    auto validfilename = FileUtils::getInstance()->fullPathForFilename(path);
    if (validfilename.size() > 0) {
        auto it = _materials.find(validfilename);
        if (it != _materials.end())
            return (Sprite3DMaterial*)it->second->clone();
        
        auto material = new (std::nothrow) Sprite3DMaterial();
        if (material->initWithFile(path))
        {
            material->_type = Sprite3DMaterial::MaterialType::CUSTOM;
            _materials[validfilename] = material;
            
            return (Sprite3DMaterial*)material->clone();
        }
        CC_SAFE_DELETE(material);
    }
    return nullptr;
}
示例#2
0
/****************************************************************************************************
战斗相关-begin
****************************************************************************************************/
bool Building::initWithBattleLogic( DBuilding * db )
{
    _type  = db->type / 100;
    _level = db->type % 100;
    setId(db->id);
    setType(db->type);
    setStatus(e_battle_status_idle);
    auto config = BuildingConfig::getBuildingConfig(db->type);
    setCoord(db->coord);
    //设置中心点
    setMidCoord(Coord(db->coord.x - config->grid,db->coord.y - config->grid));
    setHp(config->max_hp);
    if (initWithFile(BuildingCommon::getArmatureNameFromType(_type).c_str(),config->grid % 10))
    {
        setCoor(db->coord);
        updateStatus();
        return true;
    }
    return false;
}
示例#3
0
文件: TargetUnit.cpp 项目: dyvak/swtd
HealthBar* HealthBar::create(const std::string& background, const std::string& bar, float widthPerHp, int maxHp)
{
	Sprite *b = Sprite::create(bar);

	auto healthBar = new HealthBar(b, widthPerHp, maxHp);

	if (b) {	
		b->setAnchorPoint(Vec2(0, 0));
		b->setPosition(Vec2(0, 1));
		b->setScaleX(1);
		healthBar->addChild(b);
	}
	healthBar->_barFileName = bar;

	if (healthBar &&  healthBar->initWithFile(background)) {
		healthBar->autorelease();
		healthBar->setAnchorPoint(Vec2(0.5, 0));
		healthBar->setScaleX(widthPerHp * maxHp);
	}
	return healthBar;
}
示例#4
0
Dragon*  Dragon::create(std::string modelPath)
{
	auto sprite = new (std::nothrow) Dragon();
	if (sprite && sprite->initWithFile(modelPath))
	{
		sprite->_headingAngle = 0;
		sprite->_modelPath = modelPath;
		sprite->animateByState(DRAGON_IDLE);
		sprite->aiPatrol();
		sprite->autorelease();
		sprite->scheduleUpdate();
		sprite->_isPlayerInSight = false;
		sprite->_isPlayerInRange = false;
		sprite->_isAlive = true;
		sprite->_hitCount = 0;
		return sprite;
	}
	delete sprite;
	sprite = nullptr;
	return nullptr;
}
示例#5
0
TigerBaseButton* TigerBaseButton::create(const std::string& normal,
                                         const std::string& select,
                                         const std::string& disable,
                                         Widget::TextureResType type)
{
    auto ret = new (std::nothrow)TigerBaseButton();
    
    if (ret && ret->initWithFile(normal,
                                 select,
                                 disable,
                                 type))
    {
        ret->autorelease();
    }else
    {
        CC_SAFE_DELETE(ret);
        ret = nullptr;
    }
    
    return ret;
}
NS_CC_BEGIN

Animation3D* Animation3D::create(const std::string& fileName, const std::string& animationName)
{
    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
    std::string key = fullPath + "#" + animationName;
    auto animation = Animation3DCache::getInstance()->getAnimation(key);
    if (animation != nullptr)
        return animation;

    animation = new (std::nothrow) Animation3D();
    if(animation->initWithFile(fileName, animationName))
    {
        animation->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(animation);
    }

    return animation;
}
//=======================================================
//  飞絮 //season5_dandelion_15-ipadhd.png
//=======================================================
Dandelion::Dandelion(float posx,float posy,float endPosX,float endPosY)
{
    int index = 15.0f*CCRANDOM_0_1()+1;
    if (index > 15) {
        index = 15;
    }
    
    char fileName[64];
    sprintf(fileName, "dandelion_%d.png",index);
    initWithFile(resMgr->getSharedFilePath(fileName).c_str());
    
    setRotation(30);//旋转角度
    setAnchorPoint(ccp(0.5, 3));//设置精灵锚点
    setPosition(ccp(posx, posy));//叶子1第一次初始位置
    setScale(0.5);//设置叶片大小
    
    time = 10 + 10*CCRANDOM_0_1();//叶子下落的时间
    roTime = 1.5 + CCRANDOM_0_1();//叶子单向摆动一次时间
    fAngle1 = -40 - (CCRANDOM_0_1()*30);//叶子逆时针摆动角度
    fAngle2 = 40 + (CCRANDOM_0_1()*30);//顺时针摆动角度
    
    runAction(createFallAction(time, endPosX, endPosY, roTime,
                               fAngle1,fAngle2, SEL_CallFuncN(&Dandelion::arrived)));
}
示例#8
0
FLGameBlock::FLGameBlock(FLGame& pGame)
    : m_pGame(pGame)
{
    initWithFile("block.png",16);
}
SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale)
	: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _timeScale(1) {
	initWithFile(skeletonDataFile, atlasFile, scale);
}
 bool Scale9Sprite::initWithFile(const std::string& file, const Rect& rect)
 {
     return initWithFile(file, rect, Rect::ZERO);
 }
示例#11
0
PolygonSprite* PolygonSprite::spriteWithFile(const char* filename, b2Body* body, bool original)
{
	return initWithFile(filename, body, original);
}
示例#12
0
文件: Item.cpp 项目: rapito/CrossPath
Item::Item(void)
{

	initWithFile(CommonKeys::keyToString(CommonKeys::IMG_DUMMY));
	_value = 1;
}
示例#13
0
void BaseSprite::timeToDelayInit(CCNode* mySelf)
{
	initWithFile(mDelayFileName);
	mDelayFileName = "";
	setScale(1.0f);
}
示例#14
0
void TrapBomb::config( const cocos2d::ValueMap& cfg )
{
	initWithFile("eb_00.png");
	Trap::config(cfg);
}
示例#15
0
bool BaseSprite::initWithFile(string fileName)
{
	return initWithFile(fileName.c_str());
}
示例#16
0
void Planet::initWithForceSide( int force )
{
	Planet::init();
	m_nForceSide = force;
	
	// 星球
	if(force == kForceSideCat)
	{
		initWithFile("Planet_cat.png");
	}
	else if(force == kForceSideDog)
	{
		initWithFile("Planet_dog.png");
	}
	else if(force == kForceSideThird)
	{
		initWithFile("Planet_third.png");
	}
	else if(force == kForceSideMiddle)
	{
		initWithFile("Planet_middle.png");
	}
	else
	{
		return;
	}

	// 中间的脸
	CCSize planetSize = boundingBox().size;
	if(!m_pFace)
	{
		Face* pFace = Face::createWithForceSide(force);
		setFace(pFace);
		m_pFace->setPosition(ccp(planetSize.width / 2 + 3, planetSize.height / 2 - 3));
		this->addChild(m_pFace);
	}
	else
		m_pFace->initWithForceSide(force);

	
	

	// 右上角的数字
	CCString* pStr = CCString::createWithFormat("%d",  getFightUnitCount());
	if(!m_pFightUnitLabel)
	{
		setFightUnitLabel(CCLabelTTF::create(" ", FONT_00_STARMAP_TRUETYPE, 19));
        int x = planetSize.width - 16;
        int y = planetSize.height - 16;
        // 对于ios再微调一下
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
        x -= 1;
        y -= 2;
#endif
		m_pFightUnitLabel->setPosition(ccp(x, y));
		this->addChild(m_pFightUnitLabel);        
	}

	if(m_nForceSide != kForceSideMiddle)
	{
		ccColor3B ccMyOrange={255, 104, 0};
		m_pFightUnitLabel->setColor(ccMyOrange);
	}
	else
	{	
		ccColor3B ccMyGray={72, 72, 72};
		m_pFightUnitLabel->setColor(ccMyGray);
	}
	m_pFightUnitLabel->setString(pStr->getCString());


	// 每次init之后stopped都会被置为false
	// 主要是因为当把一个middel星设为stop后,被另一方占领需要自动恢复成正常增加
	m_bIncreaseStopped =false;
	// b2Body创建

	// setLevel(0);
	slowDownRestore(0);
	setScale(1);
}
示例#17
0
 PGNDatabase::PGNDatabase(const char* filepath) {
     initWithFile(filepath);
 }
示例#18
0
EndBar::EndBar(void)
{
	Bar::Bar();
	initWithFile(CommonKeys::keyToString(CommonKeys::IMG_BAR_END));
	resetPosition();
}
示例#19
0
bool Ball::init(){

    initWithFile("CloseNormal.png");
    
    return true;
}
示例#20
0
 PGNDatabase::PGNDatabase(const std::string& filepath) {
     initWithFile(filepath.c_str());
 }
示例#21
0
Mushroom* Mushroom::create(const std::string &filename){
    auto mushroom = new Mushroom();
    mushroom->initWithFile(filename);
    mushroom->autorelease();
    return mushroom;
}