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

Author Topic: Having trouble black lines with tilemaps - again  (Read 8038 times)

0 Members and 1 Guest are viewing this topic.

DevilEdge

  • Newbie
  • *
  • Posts: 28
    • View Profile
Having trouble black lines with tilemaps - again
« on: August 19, 2014, 07:27:25 pm »
Hi there, some of you may remember my earlier post about the same thing, and at the end I thought I had solved it. Unfortunately, it didn't solve my problem, and it's really starting to frustrate me. I've made a video describing my problem here: https://www.youtube.com/watch?v=km5j22YYr-Q&feature=youtu.be

As you can see, there's black lines that are inconsistently spread out across the tiles, and make the whole map look extremely ugly. My tilemap code is exactly the same as the SFML example, so what I'm wondering is if my tileset being created incorrectly is causing the issue. I've attached the tilemap below, and I'd be so grateful if someone where to test it on a machine of theirs using the tilemap and seeing if they get the same results. If this isn't the problem, any help getting started in the right direction would be great as well.

Thanks!
« Last Edit: August 19, 2014, 07:52:45 pm by DevilEdge »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Having trouble black lines with tilemaps - again
« Reply #1 on: August 19, 2014, 07:42:20 pm »
I'm not seeing the tilemap attachment for some reason ... :-(

Some random guesses/suggested tests below.

Are your graphics drivers up-to-date? If not, try the latest drivers (or older drivers).
Does this happen on different hardware as well (especially machines with other graphics cards)?
Does the same thing happen on a different OS (Mac OS, Linux)? Testing that would help narrow down if it's OS related.
Does the same thing happen with the sprite sheet in different image formats (try PNG, JPEG, others)? Would help narrow down if there's a bug related to loading different image formats.
Does the same thing happen if you build the same code with a different compiler on the same platform?
Does this happen with both release (optimized) and debug (unoptimized) builds?
Have you tried running some static code analyzers over your code + enabling more warnings from your compiler and fixing found issues? Does it still happen then?
Are you using multithreading? And if so, does it still happen in a single-threaded program?

That's what I would test first.


DevilEdge

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Having trouble black lines with tilemaps - again
« Reply #2 on: August 19, 2014, 07:56:17 pm »
I'm not seeing the tilemap attachment for some reason ... :-(

Oops, forgot to attach it haha. It should be attached now.

I can answer a couple of the questions and give some info:

1. My graphics drivers are 100% up-to-date (I have a Nvidia GTX 760)
2. I tried the program on my brother's Intel HD 3000 machine, and the same error occurs.
3. I haven't tried it on any other OS, and I don't have the resources to do so unfortunately.
4. I'm using PNG right now, I can try others as well later.
5. The same things occurs on both VS 13 and CodeBlocks 13.12.
6. This occurs on both release and debug
7. I haven't done either, I will do that soon.
8. Nope, not using any multithreading.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Having trouble black lines with tilemaps - again
« Reply #3 on: August 19, 2014, 11:19:32 pm »
black lines? they seem more like blue lines to me.
try filling the whole map with the lava tile.

edit: there's nothing wrong in your tileset. are you smoothing the texture?
« Last Edit: August 19, 2014, 11:23:42 pm by Stauricus »
Visit my game site (and hopefully help funding it? )
Website | IndieDB

DevilEdge

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Having trouble black lines with tilemaps - again
« Reply #4 on: August 19, 2014, 11:57:28 pm »
black lines? they seem more like blue lines to me.
try filling the whole map with the lava tile.

edit: there's nothing wrong in your tileset. are you smoothing the texture?

You're right, they are more blue, my bad. I just tried filling the whole map with the lava tile, and the same blue line error occurs. Regards to smoothing, I'm not smoothing it, but I tested it to see if it did anything, and boy it did. Instead of making random lines like in the video, and creates a clear space in between each tile with the blue line.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Having trouble black lines with tilemaps - again
« Reply #5 on: August 20, 2014, 03:59:52 pm »
well that's weird :/
can you post a minimal example of code that reproduces the issue, so we can test it?
Visit my game site (and hopefully help funding it? )
Website | IndieDB

DevilEdge

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Having trouble black lines with tilemaps - again
« Reply #6 on: August 20, 2014, 07:52:46 pm »
class TileMap : public sf::Drawable, public sf::Transformable
{
public:

    bool load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height)
    {
        // load the tileset texture
        if (!m_tileset.loadFromFile(tileset))
            return false;

        // resize the vertex array to fit the level size
        m_vertices.setPrimitiveType(sf::Quads);
        m_vertices.resize(width * height * 4);

        // populate the vertex array, with one quad per tile
        for (unsigned int i = 0; i < width; ++i)
            for (unsigned int j = 0; j < height; ++j)
            {
                // get the current tile number
                int tileNumber = tiles[i + j * width];

                // find its position in the tileset texture
                int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
                int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);

                // get a pointer to the current tile's quad
                sf::Vertex* quad = &m_vertices[(i + j * width) * 4];

                // define its 4 corners
                quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
                quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
                quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);

                // define its 4 texture coordinates
                quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
                quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
                quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
                quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
            }

        return true;
    }

private:

    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
        // apply the transform
        states.transform *= getTransform();

        // apply the tileset texture
        states.texture = &m_tileset;

        // draw the vertex array
        target.draw(m_vertices, states);
    }

    sf::VertexArray m_vertices;
    sf::Texture m_tileset;
};

int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(512, 256), "Tilemap");

    // define the level with an array of tile indices
    const int level[] =
    {
        0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
        1, 1, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 1, 1,
        0, 1, 0, 0, 2, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0,
        0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 2, 0, 0,
        0, 0, 1, 0, 1, 0, 2, 2, 0, 0, 1, 1, 1, 1, 2, 0,
        2, 0, 1, 0, 1, 0, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1,
        0, 0, 1, 0, 1, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1,
    };

    // create the tilemap from the level definition
    TileMap map;
    if (!map.load("spritesheet.png", sf::Vector2u(32, 32), level, 16, 8))
        return -1;

    // run the main loop
    while (window.isOpen())
    {
        // handle events
        sf::Event event;
        while (window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
                window.close();
        }

        // draw the map
        window.clear();
        window.draw(map);
        window.display();
    }

    return 0;
}

You can go ahead and use the tilemap I supplied in the first post.

Thanks!

Godsend72

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Having trouble black lines with tilemaps - again
« Reply #7 on: August 20, 2014, 08:29:49 pm »
I have the same problem and i found 2 more topics about that:

http://en.sfml-dev.org/forums/index.php?topic=6665.0

http://en.sfml-dev.org/forums/index.php?topic=15338.msg109326#msg109326

i haven't been able to solve my problem, and i used the same tile map code as you.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Having trouble black lines with tilemaps - again
« Reply #8 on: August 20, 2014, 08:36:24 pm »
http://s26.postimg.org/3u9y594nd/Example.png
All fine in example, post example picture please.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Having trouble black lines with tilemaps - again
« Reply #9 on: August 21, 2014, 03:29:23 am »
You can go ahead and use the tilemap I supplied in the first post.
Thanks!

the code you posted works for me, just like BaneTrapper's screenshot. do you get the lines in it??

edit: maybe it's related to antialiasing from your graphics card?
« Last Edit: August 21, 2014, 03:41:30 am by Stauricus »
Visit my game site (and hopefully help funding it? )
Website | IndieDB

DevilEdge

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Having trouble black lines with tilemaps - again
« Reply #10 on: August 22, 2014, 12:08:56 am »
Ok I just tested the sample version again, and I don't get the lines. So that leaves me to conclude that something about how I'm using my views is causing the problem. Here's the relevant code in my player's view:

Player.cpp:

Player::Player(const std::string& id, bool active) :
                m_viewArea(sf::Vector2f(100, 100))
        {
                m_texture.loadFromFile("Resources/player.png");
                m_sprite.setTexture(m_texture);
                m_sprite.setPosition(350, 300);

                registerAttribute("renderable", new bool(true));
                registerAttribute("health", new int(20));

                SceneManager::getView().setCenter(m_sprite.getPosition());
                SceneManager::getView().setSize(m_viewArea);
        }

bool Player::nextPosValid(const sf::Vector2f& offset)
        {
                sf::Vector2f offsettedPos(m_sprite.getPosition().x + offset.x, m_sprite.getPosition().y + offset.y);

                //The bounding rectangle of the future player
                sf::FloatRect rect(offsettedPos, sf::Vector2f(m_sprite.getGlobalBounds().width, m_sprite.getGlobalBounds().height));

                if (SceneManager::getWorld().getCurrentCell()->getTileMap().collidesWithType(2, rect))
            return false;

                return true;
        }

void Player::move(const sf::Vector2f& offset)
        {
                m_sprite.move(offset);
                SceneManager::getView().setCenter(m_sprite.getPosition());
        }

        void Player::update(sf::Time dt)
        {
                if (InputManager::isActive(User_Input::UPHOLD))
                {
                        if (nextPosValid(sf::Vector2f(0, -100 * dt.asSeconds())))
                                move(sf::Vector2f(0, -100 * dt.asSeconds()));
                }

                if (InputManager::isActive(User_Input::LEFTHOLD))
                {
                        if (nextPosValid(sf::Vector2f(-100 * dt.asSeconds(), 0)))
                                move(sf::Vector2f(-100 * dt.asSeconds(), 0));
                }

                if (InputManager::isActive(User_Input::DOWNHOLD))
                {
                        if (nextPosValid(sf::Vector2f(0, 100 * dt.asSeconds())))
                                move(sf::Vector2f(0, 100 * dt.asSeconds()));
                }

                if (InputManager::isActive(User_Input::RIGHTHOLD))
                {
                        if (nextPosValid(sf::Vector2f(100 * dt.asSeconds(), 0)))
                                move(sf::Vector2f(100 * dt.asSeconds(), 0));
                }

                if (InputManager::isActive(User_Input::PPRESS))
                {
                        getAttribute<int>("health") -= 5;

                        std::cout << "Player health is now: " << getAttribute<int>("health") << std::endl;
                }

                if (InputManager::isActive(User_Input::VHOLD))
                {
                        if (SceneManager::getView().getSize().x < 300 ||
                                SceneManager::getView().getSize().y < 300)
                                SceneManager::getView().setSize(sf::Vector2f(SceneManager::getView().getSize().x + 0.5, SceneManager::getView().getSize().y + 0.5));
                }

                else if (InputManager::isActive(User_Input::IHOLD))
                {
                        if (SceneManager::getView().getSize().x >= 100 ||
                                SceneManager::getView().getSize().y >= 100)
                                SceneManager::getView().setSize(sf::Vector2f(SceneManager::getView().getSize().x - 0.5, SceneManager::getView().getSize().y - 0.5));
                }

                if (getAttribute<int>("health") <= 0)
                        setAttribute("renderable", new bool(false));

                setPosition(m_sprite.getPosition());
                setBounds(m_sprite.getGlobalBounds());
        }

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Having trouble black lines with tilemaps - again
« Reply #11 on: August 24, 2014, 11:41:52 pm »
i have no idea so far.
don't you have anything smaller & complete, so we can simply copy/paste it and test?
otherwise we have to build the complete application and your classes (which we don't know how work) just to test it...
Visit my game site (and hopefully help funding it? )
Website | IndieDB

Xornand

  • Jr. Member
  • **
  • Posts: 78
  • C++ / Python
    • View Profile
Re: Having trouble black lines with tilemaps - again
« Reply #12 on: August 25, 2014, 12:16:31 am »
The lines show up when you apply a view whose central coordinates aren't whole numbers. In order to fix it, round up the coordinates of the view before applying it to the render window.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Having trouble black lines with tilemaps - again
« Reply #13 on: August 25, 2014, 01:10:43 pm »
In here
Code: [Select]
void Player::move(const sf::Vector2f& offset)
    {
        m_sprite.move(offset);
        SceneManager::getView().setCenter(m_sprite.getPosition());
    }

//This line
SceneManager::getView().setCenter(m_sprite.getPosition());
//Make it this
SceneManager::getView().setCenter(sf::Vector2f( std::floor(m_sprite.getPosition().x), std::floor(m_sprite.getPosition().y) ) );
I am pretty sure your are the same guy in last topic. We discussed this already. make view positions a whole number without decimal point.

Read about std::Floor here http://en.cppreference.com/w/cpp/numeric/math/floor
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

 

anything