Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Visual glitch with a tilemap [Fixed]  (Read 950 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, 10: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 15, 2018, 12:12:46 am by pw90 »

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Visual glitch with a tilemap
« Reply #1 on: June 14, 2018, 11: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
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

pw90

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Visual glitch with a tilemap
« Reply #2 on: June 14, 2018, 11: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: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Visual glitch with a tilemap [Fixed]
« Reply #3 on: June 22, 2018, 09: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
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything