Map tiles are now correctly sized and positioned. Errors from before were due to floating point being used for positioning.
This commit is contained in:
parent
2c011079a8
commit
b2d0b0ee4c
4 changed files with 34 additions and 16 deletions
|
@ -99,6 +99,8 @@ TEST_CASE("map image test", "[map-sprite]") {
|
|||
|
||||
for(auto tile : tiles) {
|
||||
sf::Vector2i coords{tile["x"], tile["y"]};
|
||||
REQUIRE(coords.x % size.x == 0);
|
||||
REQUIRE(coords.y % size.y == 0);
|
||||
sprite_coord.insert_or_assign(tile["display"], coords);
|
||||
}
|
||||
|
||||
|
@ -117,13 +119,24 @@ TEST_CASE("map image test", "[map-sprite]") {
|
|||
REQUIRE(sprite_coord.contains(display));
|
||||
|
||||
auto coords = sprite_coord.at(display);
|
||||
sf::IntRect square{coords, size};
|
||||
sf::IntRect square{coords, {size.x, size.y}};
|
||||
sf::Sprite sprite{map_sprites, square};
|
||||
sprite.setColor({150,150,150,255});
|
||||
sprite.setPosition({float(it.x) * float(size.x), float(it.y) * float(size.y)});
|
||||
sprite.setPosition({float(it.x * size.x), float(it.y * size.y)});
|
||||
render.draw(sprite);
|
||||
}
|
||||
|
||||
|
||||
level.world->query<components::Position, components::Tile>([&](auto, auto &pos, auto &entity_glyph) {
|
||||
REQUIRE(sprite_coord.contains(entity_glyph.display));
|
||||
auto coords = sprite_coord.at(entity_glyph.display);
|
||||
sf::IntRect square{coords, {size.x, size.y}};
|
||||
sf::Sprite sprite{map_sprites, square};
|
||||
sprite.setColor({255,150,150,255});
|
||||
sprite.setPosition({float(pos.location.x * size.x), float(pos.location.y * size.y)});
|
||||
render.draw(sprite);
|
||||
});
|
||||
|
||||
render.display();
|
||||
sf::Image out_img = render.getTexture().copyToImage();
|
||||
bool worked = out_img.saveToFile("map_test.png");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue