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

Author Topic: isometric grid problems  (Read 1665 times)

0 Members and 1 Guest are viewing this topic.

ka0s420

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • Email
isometric grid problems
« on: April 12, 2016, 05:25:42 am »
hi, just as an aside to what i'm developing at the moment, I decided to try out using isometric perspective. Now to achieve this i made a minimal example:


sf::RenderWindow window;
        window.create(sf::VideoMode(800, 800), "test");
        window.setFramerateLimit(60);
        sf::View view;
        view.setCenter(100, 100);
        view.setSize(800, 800);
        resourceHolder res;
        std::vector<std::vector<std::unique_ptr<sf::Sprite>>> sprites;
        for (int i = 0; i < 10; i++)
        {
                std::vector<std::unique_ptr<sf::Sprite>> b;
                sprites.push_back(std::move(b));
                for (int j = 0; j < 10; j++)
                {
                        auto a = std::unique_ptr<sf::Sprite>(new sf::Sprite);
                        a->setTexture(res.getTexture("graphics/isoGrass.png"));
                        sf::Vector2f vec(i * 32, j * 32);
                        sf::Vector2f vec2(0, 0);
                        vec2.x = vec.x - vec.y;
                        vec2.y = (vec.y + vec.x) / 2;
                        a->setPosition(vec2);
                        sprites[i].push_back(std::move(a));
                }
        }
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                        {
                                window.close();
                        }
                }
                window.setView(view);
                window.clear(sf::Color::Black);
                for (int i = 0; i < sprites.size(); i++)
                {
                        for (int j = 0; j < sprites[i].size(); j++)
                        {
                                window.draw(*sprites[i][j]);
                        }
                }
                window.display();
        }

the code above gimes me https://www.dropbox.com/s/rmp168f094v5ug1/isoGrid.jpg?dl=0 which is a diamond shaped grid as one would hope and expect. However, you'll notice that the 'cubes' are spaced out and so the grid is full of holes. Here is the png of the 'cube' https://www.dropbox.com/s/z8v5y1vcdl48l1g/isoGrass.png?dl=0

The only thing I can think is that there is something wrong with the dimensions of my 'cubes', all the tutorials i've seen simply use the formular in the above code to convert the cartesian coordinates into isometric ones, and this is working, hence the diamond shaped grid.

Any help would be greatly appreciated - thanks for your time.

ka0s420

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • Email
Re: isometric grid problems
« Reply #1 on: April 12, 2016, 05:43:53 am »
Okay, so changing the sprites scale so that they 64x64 made it so it is now seamless. problem solved. Also, this can be achieved by making the space between grid cells 16, as if the tile itself were only 16x16; This is better than scaling up perhaps, because scaling can make things look worse, if that bothers you. My current game has mouse zoom so it doesn't bother me too much ;)
« Last Edit: April 12, 2016, 06:02:25 am by ka0s420 »

 

anything