Welcome, Guest. Please login or register.

Author Topic: Visual glitch with a tilemap [Fixed]  (Read 83 times)

0 Members and 1 Guest are viewing this topic.

pw90

  • Newbie
  • *
  • Posts: 3
    • View Profile
Visual glitch with a tilemap [Fixed]
« on: June 14, 2018, 08:54:03 pm »
I'm working on a platforming game.
I have a 32x32 tilemap which uses a vertex array, my problem is that vertical lines with textures from other tiles appear when my view coordinates are odd integers (my view coordinates are always integers).

Any ideas what the problem could be? Thanks

Update:
I fixed it (thanks Hapax) by making my view the same size as my window and using sf::View::zoom instead.
« Last Edit: June 14, 2018, 10:12:46 pm by pw90 »

Hapax

  • Hero Member
  • *****
  • Posts: 2525
  • My number of posts is shown in hexadecimal.
    • View Profile
Re: Visual glitch with a tilemap
« Reply #1 on: June 14, 2018, 09:02:44 pm »
Is the view scaled or rotated at all? To avoid artifacts, the view size should match the size of the window (for integer positions).
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter

pw90

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Visual glitch with a tilemap
« Reply #2 on: June 14, 2018, 09:21:06 pm »
Thanks for the reply. My view is setup with this code:
    //Create Window
    global.window.create(sf::VideoMode(window_base_width, window_base_height), PROJECT_TITLE, sf::Style::None);
    {
        //Setup Fullscreen
        const float max_w = sf::VideoMode::getDesktopMode().width;
        const float max_h = sf::VideoMode::getDesktopMode().height;
        const float aspect = max_w / max_h;
        float new_w, new_h;
        if (max_w < max_h)
        {
            //Portrait display
            new_w = std::min<float>(window_base_width, max_w);
            new_h = new_w / aspect;
        }
        else
        {
            //Landscape display
            new_h = std::min<float>(window_base_height, max_h);
            new_w = new_h * aspect;
        }
        //Setup window view
        sf::View view;
        new_w = std::floor(new_w);
        new_h = std::floor(new_h);
        view.setSize(new_w, new_h);
        view.setCenter(new_w/2, new_h/2);
        global.window.setView(view);
        //Window position and size
        global.window.setSize(sf::Vector2u(max_w, max_h));
        global.window.setPosition(sf::Vector2i(0, 0));
    }

The view's size is not the same as the windows because of this.
So I should set the view's size to the window size and use sf::View::zoom instead of resizing it?

Hapax

  • Hero Member
  • *****
  • Posts: 2525
  • My number of posts is shown in hexadecimal.
    • View Profile
Re: Visual glitch with a tilemap [Fixed]
« Reply #3 on: June 22, 2018, 07:06:59 pm »
The zoom feature of a view merely resizes it to the zoomed size so it wouldn't help to use zoom.

The view and its integer requirements work best when the view size is matched to the size of the window so if you can do this, it's the easiest solution.
Glad to see you already have done this (just noticed your updated post).
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter