Advertisement Jump to content
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!