GAFAsset * GAFAsset::create(const std::string& jsonPath)
{
    GAFAsset *pRet = new GAFAsset();
    if (pRet && pRet->initWithImageData(jsonPath.c_str()))
    {
        pRet->autorelease();
        return pRet;
    }
    CC_SAFE_DELETE(pRet);
    return NULL;
}
void GAFAsset::getResourceReferencesFromBundle(const std::string& zipfilePath, const std::string& entryFile, std::vector<GAFResourcesInfo*>& dest)
{
    GAFAsset * asset = new GAFAsset();
    asset->m_state = State::DryRun;
    if (asset && asset->initWithGAFBundle(zipfilePath, entryFile, nullptr))
    {
        asset->parseReferences(dest);
    }
    CC_SAFE_RELEASE(asset);
    return;
}
GAFAsset* GAFAsset::create(const std::string& gafFilePath, GAFTextureLoadDelegate_t delegate, GAFLoader* customLoader /*= nullptr*/)
{
    GAFAsset * ret = new GAFAsset();
    if (ret && ret->initWithGAFFile(gafFilePath, delegate, customLoader))
    {
        ret->autorelease();
        return ret;
    }
    CC_SAFE_RELEASE(ret);
    return nullptr;
}
Beispiel #4
0
GAFAsset* GAFAsset::createWithBundle(const std::string& zipfilePath, const std::string& entryFile, GAFTextureLoadDelegate_t delegate /*= NULL*/)
{
    GAFAsset * ret = new GAFAsset();
    if (ret && ret->initWithGAFBundle(zipfilePath, entryFile, delegate))
    {
        ret->autorelease();
        return ret;
    }
    CC_SAFE_RELEASE(ret);
    return nullptr;
}
Beispiel #5
0
bool Gun::init(const std::string& name)
{
    bool ret = true;
    {
        cocos2d::__Dictionary* params = cocos2d::__Dictionary::createWithContentsOfFile(name.c_str());

        if (!params)
            return false;

        std::string modelName = params->valueForKey("model")->_string;

        GAFAsset* asset = GAFAsset::create(modelName);
        if (!asset)
            return false;

        m_model = asset->createObjectAndRun();
        m_model->retain();
        Vec2 position(Vec2(params->valueForKey("pivot_x")->floatValue(), params->valueForKey("pivot_y")->floatValue()));
        m_model->setPosition(position);
        m_model->playSequence("idle", true);
        m_model->setSequenceDelegate(this);
        addChild(m_model);

        std::string projectileName = params->valueForKey("projectile")->_string;
        m_projectile = GAFAsset::create(projectileName);
        if (m_projectile)
            m_projectile->retain();

        m_shootDelay = params->valueForKey("shoot_delay")->floatValue();
        m_projectileSpeed = params->valueForKey("projectile_speed")->floatValue();
        m_projectileDamage = params->valueForKey("damage")->floatValue();
        m_reloadTime = params->valueForKey("reload_time")->floatValue();

        m_projectileOffset = Vec2(params->valueForKey("projectile_pivot_x")->floatValue(), params->valueForKey("projectile_pivot_y")->floatValue());
        m_emissionPoint = Vec2(params->valueForKey("emission_point_x")->floatValue(), params->valueForKey("emission_point_y")->floatValue());

        Director::getInstance()->getScheduler()->scheduleUpdate(this, 1, false);
    }
    return true;
}