SFML community forums

Help => General => Topic started by: Dreamflask on April 11, 2015, 02:18:12 am

Title: Wrong position in View
Post by: Dreamflask 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);
 
Title: Re: Wrong position in View
Post by: G. on April 11, 2015, 03:53:25 am
What if you don't add your offset? :p
Title: Re: Wrong position in View
Post by: Dreamflask 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)