[SOLVED] Top Down Parallax scrolling and a zoomable camera

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
randomnovice
Party member
Posts: 126
Joined: Sat May 09, 2015 9:15 pm

[SOLVED] Top Down Parallax scrolling and a zoomable camera

Post by randomnovice »

Hi folks,

I'm playing around with a little 2d space game and I've got stuck on some maths -- can anyone help?

I'm trying to include a background image that moves at a slower speed that the foreground objects (1/4 speed).
It's a space image that I've tiled to always fill the screen.
That works fine as far as it goes but...

Because my camera has a zoom function (press =/- keys) it quickly looks wrong on other zoom settings, as if objects are moving away from you in relation to the background.

I suspect I also need to draw my background image zoomed but by how much? It's supposed to be a long, long way in the distance.

Maths fail.

The project is attached.
Controls:
Move: Arrows
Fire weapon: Space
Toggle Local Map: L
Zoom in: = key
Zoom out: - key
(zoom map using [ and ])
Attachments
Cosmos.love
(13.57 MiB) Downloaded 122 times
Last edited by randomnovice on Fri Nov 15, 2019 2:35 pm, edited 1 time in total.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Top Down Parallax scrolling and a zoomable camera

Post by raidho36 »

When you zoom the camera you multiply all values by the zoom factor, in foreground and in background.
randomnovice
Party member
Posts: 126
Joined: Sat May 09, 2015 9:15 pm

Re: [SOLVED] Top Down Parallax scrolling and a zoomable camera

Post by randomnovice »

Okay - I've tweaked it a bit and I think it's okay. Thanks.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: [SOLVED] Top Down Parallax scrolling and a zoomable camera

Post by pgimeno »

There are two types of zoom. One consists of bringing the camera closer to the target; some 3D design programs do this when you zoom. The other consists of magnifying a small angle of view so it looks bigger; that's what zoom lenses and telescopes do. Playing with both in a real camera, you can get effects such as this one: http://www.formauri.es/personal/pgimeno ... -demo2.jpg

With the first type of zoom, the background would not be altered. With the second, it would. It's a question of choosing the one that looks right, which is something you seem to have managed :)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 52 guests