[HELP] Proper scaling methods..

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
roccdcasbah
Prole
Posts: 5
Joined: Thu Feb 23, 2017 12:02 pm

[HELP] Proper scaling methods..

Post by roccdcasbah »

Hello! Long time lurker, first time posting here!
Am also a total newbie to lua scripting ( about 6 months ).

Also sorry for the bad code formatting in this post, cant seem to figure out how to properly copy-paste my code unto here! :ultrahappy:

Im having a hard time figuring out how to scale up my project to window size.

I´ve been working on a small game for a while and have always intended to run it in a 256x256px window but thought that it would look nicer to run fullscreen and scale it up by using nearest neighbour interpolation, for that lofi look.

Now I´ve tried using love.graphics.scale to blow up the coord system and all that but cant seem to figure it out, I´ve also been considering using a camera library for this, like kikitos gamera or hump.camera. My main problem is figuring out how to wrap my draw functions correctly for this to work, i´ve been using https://github.com/tanema/light_world.lua for lighting and this bad boy is reacting very badly to my attempts to implement scaling or camera modules. Guess I should implement camera and scaling stuff earlier in development BEFORE he project is cluttered with mediocre code!

Anyway..
Heres how my draw functions look:

First i have a ghetto gamestate engine that draws the appropriate stuff for the occasion:

Code: Select all

function gamestate.draw(a)
if a == "1" 
then
 lightWorld:draw(function()
 chunkDraw()
 enemy.draw()
 items.draw()
 player_draw()
 ChunkDrawExtras()
 end)
And in the main loops i call:

Code: Select all

function love.draw()
gamestate.draw(currentState)
end
Now, with kikitos gamera for example i tried to set up a new camera ( been using gamera before and it worked beautifully, but i seem to run into problems when combining it with tanemas light_world) and drawing it like this:

Code: Select all

-- Under love.draw() in main.lua
cam:draw(function(l,t,w,h)
gamestate.draw(currentState)
end)
or inside the gamestate script like this:

Code: Select all

function gamestate.draw(a)
if a == "1" 
then
cam:draw(function(l,t,w,h)
	 lightWorld:draw(function()
 	 chunkDraw()
 	 enemy.draw()
 	 items.draw()
         player_draw()
         chunkDrawExtras()
end)
end)

Now what happens when i try these things are that some things are scaling up correctly and some just bug out completely, Im guessing i have to translate some coordinates somewhere but im totally missing where.

Also tried to love.graphics.push() and scale everything with love.graphics.scale and then pop it before drawing ui...

Hope this made any sort of sense.. Because it doesnt make sense to me! :ultrahappy:

Cheers!
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: [HELP] Proper scaling methods..

Post by Positive07 »

I suggest you take a look at push.

Also if you want to make your own camera, draw your game to the size you want in a canvas, then Canvas:setFilter to nearest and draw that to the screen scaled up. Then you should most likely scale your mouse coordinates down to the world coordinates (by dividing by the scaling ammounts)
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
roccdcasbah
Prole
Posts: 5
Joined: Thu Feb 23, 2017 12:02 pm

Re: [HELP] Proper scaling methods..

Post by roccdcasbah »

That looks interesting, gonna give it a try!

Thanks!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests