Problem with In-Game Zooming [SOLVED]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Archiboldian C.
Prole
Posts: 10
Joined: Sun Mar 13, 2011 12:52 pm
Location: UK
Contact:

Problem with In-Game Zooming [SOLVED]

Post by Archiboldian C. »

I've recently been trying to make a game which involves a planet and the simulated inhabitance there-of, and have had some troubles with using love.graphics.scale to zoom in and out with the middle scroller mouse button thing.
I have it changing a variable up or down depending on which way you scroll and I have it zooming in an out, but I can't figure out how to stop love.graphics.scale from scaling everything else after the planet and it's inhabitants, so the mouse (which obviously has to go over everything) is scaled with the rest of it.

I tried doing

Code: Select all

love.graphics.scale(1)
to set the graphics' scale back to normal before it draws the mouse but that didn't do anything.

I'm welcome to any alternatives to love.graphics.scale and some help with layering different things in the same way you can layer movieclips in flash.
I had a look into framebuffers but got a bit confused due to the lack of examples on the wiki.
Here's the perpetrator:

Code: Select all

if area == "ingame" then
	love.graphics.scale(scale)
	love.graphics.setColor(51, 204, 102, 255)
	love.graphics.setBlendMode("alpha")
	love.graphics.setColorMode("modulate")
	love.graphics.circle("fill", 640, 400, 500, 500)
end

love.graphics.scale(1)
love.graphics.draw(p, 0, 0)
Thanks :crazy:
J
Last edited by Archiboldian C. on Mon Mar 14, 2011 8:02 pm, edited 1 time in total.
User avatar
EmmanuelOga
Citizen
Posts: 56
Joined: Thu Apr 22, 2010 9:42 pm
Location: Buenos Aires, Argentina
Contact:

Re: Problem with In-Game Zooming

Post by EmmanuelOga »

The reason is that love.graphics.scale operates in the current scale. So if you first scaled everything up 2x, then you'll need to scale down 0.5 to get back to normal. An even better method is pushing and popping the scale/translation settings. Something like:

Code: Select all

  love.graphics.push() -- saves current state
  love.graphics.scale(scale) -- scales everything
  renderScaledStuff()
  love.graphics.pop() -- restores original scale   
  renderNormalStuff()
The nice thing is that you can push and pop as many times as you want.
--------------------------------------------------------------------------------------------------------
http://EmmanuelOga.com
User avatar
Archiboldian C.
Prole
Posts: 10
Joined: Sun Mar 13, 2011 12:52 pm
Location: UK
Contact:

Re: Problem with In-Game Zooming

Post by Archiboldian C. »

Bloody frigging excellent. :o
Thank you
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 45 guests