# scrolling 2D isometric camera with a mouse

This topic is 1273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey all, i've been messin with a little isometric engine. It's been over a decade since I wrote one although i'm very familiar with standard tilemaps. I was following a tutorial which has gone well but i've hit a little bit of a hump - the writers solution to an isometric environment is to do everything as you would for a standard (Cartesian ?) tile map, literally everything, and then at the very end when rendering you convert the Cartesian positions to isometric co-ordinates.

eg, calculate your standard tile positions for the tile about to draw: tile_x = tx * tilewidth; tile_y = ty * tileheight;  then do your usual camera offsets for smooth scrolling etc tile_x += camera.x % tilewidth; etc etc and when you're all done convert to iso: iso_x = tile_x - tile_y; iso_y = (tile_x + tile_y) / 2;

This works fine when your camera is following an object IN the isometric world. IE if your camera follows a character and you press right arrow to move player right then your character will walk diagonally down and right and the world would scroll as you expect.

But I want a free camera controlled by the mouse - its a strategy game and there is "no player" in the game world. I want if you click and drag you scroll the map. BUT because everything is done Cartesian and then converted iso if you click and drag to the left intending to scroll the world right it instead scrolls diagonally down and right which is NOT where you are dragging and it feels awful.

Any ideas how can i take the position of the camera and calculate a) the tile offsets so the correct part of the map draws and b) the pixel offset for smooth scrolling in a way that feels natural? I'm beginning to think this converting everything at the end for render isnt the best idea ever :/

Edited by PanicRave

##### Share on other sites

that will keep me busy for a little while! thanks!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634150
• Total Posts
3015808
×