1
General / VertexArray, tilemap and mouse on tile
« on: August 27, 2019, 05:29:49 pm »
Hello
I have a problem with checking which tile the mouse is on. I found one solution which is already implemented, but makes a huge drop down of fps ammount. I just make an adtional VertexArray and use "contains" method. Could u tell me maybe another way to do this?
I have VertexArray of 2304 elements which makes 576 tiles.
The structure is:
Code:
And code of LoadTileMap function (i know it's not best and probably could be in one loop )
@edit
Okey, i got an idea:
I have a problem with checking which tile the mouse is on. I found one solution which is already implemented, but makes a huge drop down of fps ammount. I just make an adtional VertexArray and use "contains" method. Could u tell me maybe another way to do this?
I have VertexArray of 2304 elements which makes 576 tiles.
The structure is:
Code:
(click to show/hide)
And code of LoadTileMap function (i know it's not best and probably could be in one loop )
(click to show/hide)
@edit
Okey, i got an idea:
sf::Vector2i mouse = sf::Mouse::getPosition(window);
sf::Vector2f mouse_world = window.mapPixelToCoords(mouse);
cout << int(mouse_world.x / 60) << " " << int(mouse_world.y / 60)<< endl;
Dividing position by tilesize. But i dont know how to use this information to get to the proper tile and change for example its color.sf::Vector2f mouse_world = window.mapPixelToCoords(mouse);
cout << int(mouse_world.x / 60) << " " << int(mouse_world.y / 60)<< endl;