1
General / 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?
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);
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);