Skip to content

artifacts with 128px tile maps #175

Description

@GuidoBisocoli

I've migrated my code from tmxLoader to tmxLite and I'm having some artifacts when scrolling my map in game, sometimes some lines appear like this:

Image

I'm using the SFML3Example but I think the problem is not there, from what I understand. This does not happen with 64px maps. I was considering recreating my map as a 64px map but maybe this is trivial to solve and also can help others.

EDIT: this is my code, it's a simple VS2022 project just to test this issue

#include "tmxLoader.h" // this is the SFML3Example

#include "SFML/Graphics.hpp"
#include "SFML/Graphics/Color.hpp"
#include "SFML/System.hpp"
#include <SFML/Window/Event.hpp>
#include <SFML/Window/Keyboard.hpp>

int main()
{
sf::RenderWindow window;
window.create(sf::VideoMode(sf::Vector2u(1680, 1050)), "SFML window");

tmx::Map map;
map.load("assets/practice.tmx"); // 128px map made in Tiled!

MapLayer layerZero(map, 0);
MapLayer layerOne(map, 1);
MapLayer layerTwo(map, 2);

sf::View view;
view.setSize({ 1680*2, 1050*2});
view.setCenter(sf::Vector2f(840.f, 525.f));
sf::Vector2f pos = view.getCenter();

sf::Clock globalClock;
sf::Time elapsed;

while (window.isOpen())
{
    elapsed = globalClock.restart();
    layerZero.update(elapsed);
    layerOne.update(elapsed);
    layerTwo.update(elapsed);

    while (const std::optional event = window.pollEvent())
    {
        if (event->is<sf::Event::Closed>())
            window.close();

        else if (const auto* keyPressed = event->getIf<sf::Event::KeyPressed>())
        {
            if (keyPressed->scancode == sf::Keyboard::Scancode::W)
                pos.y -= 2600.f * elapsed.asSeconds();
            if (keyPressed->scancode == sf::Keyboard::Scancode::A)
                pos.x -= 2600.f * elapsed.asSeconds();
            if (keyPressed->scancode == sf::Keyboard::Scancode::S)
                pos.y += 2600.f * elapsed.asSeconds();
            if (keyPressed->scancode == sf::Keyboard::Scancode::D)
                pos.x += 2600.f * elapsed.asSeconds();
        }
    }

    view.setCenter({ pos.x, pos.y });

    window.setView(view);

    window.clear(sf::Color::Blue);
    window.draw(layerZero);
    window.draw(layerOne);
    window.draw(layerTwo);

    window.display();
}

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions