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

Author Topic: Question about drawing tilemaps on a modified view  (Read 1060 times)

0 Members and 1 Guest are viewing this topic.

CowNation

  • Newbie
  • *
  • Posts: 20
    • View Profile
Question about drawing tilemaps on a modified view
« on: May 02, 2018, 12:10:58 am »
I can't figure out how to draw a tilemap centered at the origin of the window with a modified view.
Here is my modified view:
View view;
view.setCenter(Game::Entity::g_eLocal.sprite.getPosition());
view.setSize(((float)Engine::windowSize.x), ((float)Engine::windowSize.y));
view.zoom(0.75);
window->setView(view);
My TileMap class:
https://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php#example-tile-map
Here is my tilemap:
TileMap TM;
if (!TM.load("Data//Images//64x64grass.png", sf::Vector2u(32, 32), level, 16, 8)) { return -1; }
When I draw the tilemap, it doesn't set it to the origin of the current view.

I have determined that the view zoom is messing it up:
zoom = 1 works perfectly:
https://i.imgur.com/0dSloIz.png
zoom = 0.75 does not:
https://i.imgur.com/KidZMNY.png
it does not update the origin of the window


Also, how do i set the top left corner of the tilemap to the origin of the window?

CowNation

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Question about drawing tilemaps on a modified view
« Reply #1 on: May 02, 2018, 12:13:23 am »
Edit: Solved. I'm literally mentally disabled.
Solution:
TM.setPosition(window->mapPixelToCoords(Vector2i(0, 0)));