[HELP] Gamera Won't Center Camera on Player

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
myogaman
Prole
Posts: 3
Joined: Tue Sep 19, 2017 3:42 am

[HELP] Gamera Won't Center Camera on Player

Post by myogaman »

Hello everyone! I jumped into LOVE about 2 weeks ago and have been making really good progress. I got lighting, states, sprite animations, a resolution handler, and GUI buttons. A lot quicker progress than when I was jumping around in Python.

However I'd like a camera that can zoom and pan, so Gamera looked perfect. However I can't make it work for the life of me. I can get the camera window to appear but not pan with character movement. It seems like the setPosition() function isn't working.

I'm relatively horrible at math and am quickly learning tons of new game concepts, so it is entirely possible I'm just coding wrong. But after two days of grinding and paring down my code, I still got nothing.

If someone could please take a look at my code, I'd really appreciate it. If it's something obvious that has to do with creating the world, or setting up the window or camera, please explain it like I'm 5.

Thank you!
Attachments
gamera_borked.love
(45.91 KiB) Downloaded 149 times
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [HELP] Gamera Won't Center Camera on Player

Post by kikito »

Hi there, it is working as expected, and following the player. It is not very noticeable because you have no background at all. It is much easier to see if you add some static background:

Code: Select all

local draw_f = function (l,t,w,h)
    hero.sprite:draw(hero.x,hero.y)
    love.graphics.rectangle('line', 100, 100, 100, 100)
    love.graphics.rectangle('line', 300, 300, 300, 300)
end
That way you will be able to see how the player is moving around the world and the camera is following him, it is not "fixed".

The other thing you might want to change is the camera window. Right now is 10, 10, 520, 580. You might want to change it so that it matches your screen dimensions:

Code: Select all

cam1:setWindow(0,0,love.graphics.getDimensions())
(You can also just comment out the setWindow line, gamera will do this by default)
When I write def I mean function.
myogaman
Prole
Posts: 3
Joined: Tue Sep 19, 2017 3:42 am

Re: [HELP] Gamera Won't Center Camera on Player

Post by myogaman »

I put a real background down and see that my code does work in my above example. So hurp durp there.

I then began to slowly strip and unravel my mess of initial code (the first draft is always the roughest, right) and discovered that Push and LOVE were applying a scale that were completely skewing my character's movement (since he's now moving 2 - 4x more than the camera). I also was setting the camera's position to (player.x, player.x). So I'm freaking awesome at this whole programming thing.

Thanks for being so awesome and patient with us newbies. The initial learning curve is always the roughest ;D
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 48 guests