dune2themaker4j
dune2themaker4j copied to clipboard
Zoom in/out on battlefield
Much like OpenTTD does and as you can see Dune 2 - The Golden Path (see: https://youtu.be/NXmXSdDd95E?t=1m39s)
Comment on the internet, of slick2d, might help.
Use graphics
class to scale all the things at once.
This gives a rough idea to render things:
I just got it working in a project I'm working on. The idea was kind of in the back of my mind for a while and I was going to implement it later but it's not so difficult.
So the way I do it is I have a gameScale variable that will represent how much I want to zoom. It increases or decreases with key presses and so forth.
I also have a camera that translates the screen so that my game character is centered. All you have to do is this:
First there is a certain amount you have to translate to center your character and that value must be modified to work with the new scaling.
The most common way is this:
charScreenCenterX = screenWidth/2f - charPosX;
charScreenCenterY = screenHeight/2f - charPosY;
If you change the scale of the game you modify those above values to:
charScreenCenterX = screenWidth/gameScale/2f - charPosX;
charScreenCenterY = screenHeight/gameScale/2f - charPosY;
Now that you have the correct translate position you can start rendering everything!
g.scale(gameScale, gameScale);
g.translate(charScreenCenterX, charScreenCenterY);
// Render your character and other stuff here!
g.resetTransform();
And that's it, this should scale your entire game and keep your character centered on screen.
Good luck!
From here: http://slick.ninjacave.com/forum/viewtopic.php?t=3817