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

Author Topic: VertexArray, tilemap and mouse on tile  (Read 1117 times)

0 Members and 2 Guests are viewing this topic.

pk3741

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
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:
(click to show/hide)

And code of LoadTileMap function (i know it's not best and probably could be in one loop :D)
(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.
« Last Edit: August 27, 2019, 06:47:59 pm by pk3741 »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: VertexArray, tilemap and mouse on tile
« Reply #1 on: August 28, 2019, 12:23:56 am »
You'll need to subtract the offset (if it has one) before dividing by the tile size.

Is your tile map transformable? If so, you'll need to do the calculations on its local co-ordinates (i.e. before transformations). To transform a point (for example, the mouse position after mapping) into the tile map's local co-ordinates, you can use its inverse transform.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything