You can now set a sprite as a background in Background which will simplify a lot of games that just place sprites over a single image.
This commit is contained in:
parent
6fb20c5085
commit
e1d61dc2c1
9 changed files with 79 additions and 22 deletions
|
|
@ -121,8 +121,36 @@ namespace guecs {
|
|||
assert(shape != nullptr && "failed to make rectangle");
|
||||
}
|
||||
|
||||
void Background::set_color(sf::Color c) {
|
||||
color = c;
|
||||
}
|
||||
|
||||
void Background::set_sprite(const std::string& name, bool stretch) {
|
||||
auto sprite_texture = BACKEND->texture_get(name);
|
||||
|
||||
sprite = make_shared<sf::Sprite>(
|
||||
*sprite_texture.texture,
|
||||
sprite_texture.sprite->getTextureRect());
|
||||
|
||||
sprite->setPosition({float(x), float(y)});
|
||||
|
||||
if(stretch) {
|
||||
auto bounds = sprite->getLocalBounds();
|
||||
|
||||
sprite->setScale({
|
||||
float(w) / bounds.size.x,
|
||||
float(h) / bounds.size.y});
|
||||
}
|
||||
}
|
||||
|
||||
void Background::render(sf::RenderWindow& window) {
|
||||
window.draw(*shape);
|
||||
if(shape != nullptr) {
|
||||
window.draw(*shape);
|
||||
}
|
||||
|
||||
if(sprite != nullptr) {
|
||||
window.draw(*sprite);
|
||||
}
|
||||
}
|
||||
|
||||
void Effect::init(lel::Cell &cell) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue