Exemplo n.º 1
0
AnimatedSpritePrivate::AnimatedSpritePrivate(): SpritePrivate()
{
    animationTime = 0;
    currentFrame = 0;
    singleShot = false;
    animationStarted = false;
    speed = 1.0f;
    region = TextureRegion(boost::shared_ptr<AnimatedTexture>());
}
Exemplo n.º 2
0
void Label::processMain()
{
    RANGERS_D(Label);
    if (!d->font)
        return;
    lock();

    if (!d->wordWrap)
        d->region = TextureRegion(d->font->renderText(fromUTF8(d->text.c_str())));
    else
        d->region = TextureRegion(d->font->renderText(fromUTF8(d->text.c_str()), d->width));

    if (!d->fixedWidth)
        d->width = d->region.texture->width();
    if (!d->fixedHeight)
        d->height = d->region.texture->height();

    unlock();
    Sprite::processMain();
}
Exemplo n.º 3
0
TextureRegion SpriteSheet::createRegion(sf::Image image)
{
    sf::Vector2u imgSize = image.getSize();
    if(imgSize.x != this->spriteSize.width || imgSize.y != this->spriteSize.height)
    {
        return TextureRegion(); 
    }
    texture.update(image,currCol*spriteSize.width, currRow*spriteSize.height);
    TextureRegion returnRegion = TextureRegion(&texture,sf::IntRect(currCol*spriteSize.width,currRow*spriteSize.height,spriteSize.width,spriteSize.height));
    currCol++;
    if(currCol >= maxcol)
    {
        currCol = 0;
        currRow++;
        if(currRow >= maxrow)
        {
            currRow = 0; //just wrap it back. graphics error is better than runtime.
        }
    }
    return returnRegion;
}
Exemplo n.º 4
0
/*!
 * \param texture texture
 * \param parent object parent
 */
AnimatedSprite::AnimatedSprite(boost::shared_ptr<AnimatedTexture> texture):
    Sprite(*(new AnimatedSpritePrivate()))
{
    RANGERS_D(AnimatedSprite);
    d->region = TextureRegion(texture);
    if (texture)
    {
        d->width = texture->width();
        d->height = texture->height();
        start();
    }
}
Exemplo n.º 5
0
/*!
 * \param animation animation resource name
 * \param parent object parent
 */
AnimatedSprite::AnimatedSprite(const std::string& animation):
    Sprite(*(new AnimatedSpritePrivate()))
{
    RANGERS_D(AnimatedSprite);
    boost::shared_ptr<AnimatedTexture> animTexture = ResourceManager::instance().loadAnimation(animation);
    d->region = TextureRegion(animTexture);
    if (animTexture)
    {
        d->width = animTexture->width();
        d->height = animTexture->height();
        start();
    }
    markToUpdate();
}
Exemplo n.º 6
0
		/// <summary>
		/// カーソルのスタイルを設定します。
		/// </summary>
		/// <param name="_type">
		/// カーソルの種類
		/// </param>
		/// <param name="_texture">
		/// カーソルとして使用する TextureRegion
		/// </param>
		/// <param name="_center">
		/// カーソルの中心位置のオフセット
		/// </param>
		CursorStyle(CursorType _type = CursorType::Default, const TextureRegion& _texture = TextureRegion(), const Point& _center = Point::Zero)
			: type(_type)
			, texture(_texture)
			, center(_center) {}
Exemplo n.º 7
0
    std::shared_ptr<TextureAtlas> GdxTextureAtlasLoader::load(std::istream& in) const
    {
        assert(_textureManager);

        auto atlas = std::make_shared<TextureAtlas>();
        std::string line;

        // texture name
        while(line.empty())
        {
            std::getline(in, line);
            StringUtils::trim(line);
        }
        if(_textureManager)
        {
            atlas->setTexture(_textureManager->load(line));
        }

        bool inRegion = false;
        TextureRegion region;

        while(in)
        {
            std::getline(in, line);
            std::size_t sep = line.find(':');
            std::string n = line.substr(0, sep);
            std::string v = line.substr(sep+1);

            if(!inRegion)
            {
                if(sep == std::string::npos)
                {
                    inRegion = true;
                    region = TextureRegion();
                    region.name = line;
                }
                else
                {
                    // header value
                }
            }
            else
            {
                if(line.substr(0, 1) == " ")
                {
                    StringUtils::trim(n);
                    StringUtils::trim(v);
                    if(n == "rotate")
                    {
                        region.rotate = v == "true";
                    }
                    else if(n == "xy")
                    {
                        sep = v.find(',');                       
                        region.x = std::stoi(v.substr(0, sep));
                        region.y = std::stoi(v.substr(sep+1));
                    }
                    else if(n == "size")
                    {
                        sep = v.find(',');
                        region.width = std::stoi(v.substr(0, sep));
                        region.height = std::stoi(v.substr(sep+1));
                    }
                    else if(n == "orig")
                    {
                        sep = v.find(',');
                        region.originalWidth = std::stoi(v.substr(0, sep));
                        region.originalHeight = std::stoi(v.substr(sep+1));
                    }
                    else if(n == "offset")
                    {
                        sep = v.find(',');
                        region.offsetX = std::stoi(v.substr(0, sep));
                        region.offsetY = std::stoi(v.substr(sep+1));
                    }
                    else if(n == "index")
                    {
                        region.index = std::stoi(v);
                    }
                }
                else
                {
                    region.origin = TextureRegion::Origin::TopLeft;
                    atlas->addRegion(region);
                    region = TextureRegion();
                    region.name = line;
                }             
            }
        }

        return std::move(atlas);
    }