Page 1 of 1

Space ship game help

Posted: Fri Apr 25, 2014 8:16 am
by HugoBDesigner
I'm putting in a generic subject for this thread because I might ask for more help on this game.
I'm making a simple (for now) space game. There is nothing wrong with the gameplay itself. My problem now is with the camera:

1. I want it to follow the ship. I got it working, but I also want to zoom in/out it. I'm using love.graphics.scale for the zoom, and for the follow-player movement I'm using love.graphics.translate. But how can I make the camera zoom in/out centralized?

Code: Select all

local newx = ship.x+ship.size/2-scrW/2
local newy = ship.y+ship.size/2-scrH/2
love.graphics.scale(zoomfactor, zoomfactor)
love.graphics.translate(-newx+scrW*zoomfactor/scrW, -newy+scrH*zoomfactor/scrH)

2. I'm making it follow the ship by always having it in the center of the image. Is it a good method, or should I add an offset to the ship to move on the camera?


Thanks for the answers!

Re: Space ship game help

Posted: Fri Apr 25, 2014 5:12 pm
by Johannes
I'm actually working on something similar (also for a space game). I got a camera working that allows you Pan/Rotate/Zoom: http://love2d.org/forums/viewtopic.php?f=4&t=77807

It basically works by generating a transformation matrix which is then applied to all x/y coordinates in the level. Take a look at camera.lua's computeMatrix function.

*EDIT* hmm, after looking through the wiki a bit and chatting with bartbes on the irc it does seem like what I'm doing is basically re-inventing the wheel a bit, and the love.graphics functions for transformation would probably work just as well :D

Re: Space ship game help

Posted: Fri Apr 25, 2014 6:04 pm
by HugoBDesigner
I"m trying to make it by myself. Not that I didn't like yours, it has a lot of cool functions, but I want it to be made using these variables, so I can edit/change them more easily. Thanks for your answer, though! If I don't get any other solution, I might use your library ;)

Re: Space ship game help

Posted: Fri Apr 25, 2014 10:13 pm
by Johannes
I'm probably going to rework mine to use the built-in love.graphics. If you want to look at a library I would probably suggest checking out hump's camera instead: http://vrld.github.io/hump/#hump.camera - that's probably what I'll be using, if I don't make my own.