Reduida la dependencia de PathSprite a Sprite
Treballant en els missatges de text que ixen durant la partida
This commit is contained in:
@@ -139,16 +139,30 @@ void Text::write(int x, int y, const std::string &text, int kerning, int lenght)
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe texto en pantalla
|
||||
void Text::write2X(int x, int y, const std::string &text, int kerning)
|
||||
{
|
||||
int shift = 0;
|
||||
for (size_t i = 0; i < text.length(); ++i)
|
||||
{
|
||||
auto index = static_cast<size_t>(text[i]);
|
||||
SDL_Rect rect = {offset_[index].x, offset_[index].y, box_width_, box_height_};
|
||||
sprite_->getTexture()->render(x + shift, y, &rect, 2.0f, 2.0f);
|
||||
shift += (offset_[index].w + kerning) * 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Escribe el texto en una textura
|
||||
std::shared_ptr<Texture> Text::writeToTexture(const std::string &text, int kerning)
|
||||
std::shared_ptr<Texture> Text::writeToTexture(const std::string &text, int zoom, int kerning)
|
||||
{
|
||||
auto renderer = Screen::get()->getRenderer();
|
||||
auto texture = std::make_shared<Texture>(renderer);
|
||||
auto width = lenght(text, kerning);
|
||||
texture->createBlank(width, box_height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
auto width = lenght(text, kerning) * zoom;
|
||||
auto height = box_height_ * zoom;
|
||||
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
texture->setAsRenderTarget(renderer);
|
||||
write(0, 0, text, kerning);
|
||||
zoom == 1 ? write(0, 0, text, kerning) : write2X(0, 0, text, kerning);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user