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

Author Topic: Wrong position in View  (Read 1424 times)

0 Members and 2 Guests are viewing this topic.

Dreamflask

  • Newbie
  • *
  • Posts: 8
    • View Profile
Wrong position in View
« on: April 11, 2015, 02:18:12 am »
Hi, I am currently working on a tile-map-editor (copy function), but I can not set up the right Sprite position in my MapView. Here is my Code i am currently using,  it is working UNTIL i change the View (move, zoom ...) and i do not get it working by myself or with google research.
Do you have some suggestions for me?

//Get the window mouse position
                                sf::Vector2f worldCoords = _window.mapPixelToCoords(mousePosition,_mapView);

                                //Convert to tile Position (chunksize = tilesize)
                                worldCoords.x = static_cast<int>((worldCoords.x / chunksize))*chunksize;
                                worldCoords.y = static_cast<int>((worldCoords.y / chunksize))*chunksize;

                                //Add offset (ix, iy) on converted tile-paste-position
                                worldCoords.x += (ix*chunksize);
                                worldCoords.y += (iy*chunksize);

                                //Set new position
                                newTile.setPosition(worldCoords);
 
« Last Edit: April 11, 2015, 02:41:34 am by Dreamflask »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Wrong position in View
« Reply #1 on: April 11, 2015, 03:53:25 am »
What if you don't add your offset? :p

Dreamflask

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Wrong position in View
« Reply #2 on: April 11, 2015, 12:15:25 pm »
The offset is needed for the current tile-position.
I copy a rectangle, then i paste it at mouse position.
So i copying tile for tile from old rect to new rect. In my array all is right, but i need to set the new Vertexarray position and this fails when i have moved the view or zoomed.

Here I paste you the full function:
(click to show/hide)