An example for love.graphics.getModes() ?

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
pnpbios
Prole
Posts: 5
Joined: Wed Sep 10, 2008 7:02 pm

An example for love.graphics.getModes() ?

Post by pnpbios »

Hi all, I've been having a blast using love2D to learn LUA. The project I am currently working on is a SHMUP and I plan on putting it in an arcade cabinet. Right now though, i'm still learning the ins and outs of lua, and i'm having problems with love.graphics.getModes().

Could somebody explain to me how to use this function?


Thanks :ugeek:
surtic
Citizen
Posts: 74
Joined: Sat Jul 12, 2008 12:18 am

Re: An example for love.graphics.getModes() ?

Post by surtic »

love.graphics.getModes returns a table which is something like {{width=..., height=...}, {width=..., height=...}, ...}.

I've attached a small program to show the modes:

Code: Select all

function load()
   modes = love.graphics.getModes()
   local font = love.graphics.newFont(love.default_font)
   love.graphics.setFont(font)
end

function draw()
   -- modes is {{width=..., height=...}, {width=..., height=...}, ...}
   for i, mode in ipairs(modes) do
      local desc = string.format("mode %d: %dx%d", i, mode.width, mode.height)
      love.graphics.draw(desc, 10, i * 20)
   end
end
Attachments
getmodes.love
(333 Bytes) Downloaded 269 times
pnpbios
Prole
Posts: 5
Joined: Wed Sep 10, 2008 7:02 pm

Re: An example for love.graphics.getModes() ?

Post by pnpbios »

Thank you very much! That looked somewhat like my code that I originally had.

Code: Select all

function load()

	x = love.graphics.getModes()
	
end

function update(dt)
end

function draw()
	local i = 0
	for w,h in pairs(x) do
		local drawStr = w.." "..h
		love.graphics.draw(drawStr,0,i*20)
		i = i +1
	end
end
Looks like I need to work on my fundamentals. Does anybody know any good lua tutorials?

I've had a lot of experience with python in the past, as well as c and c++, Lua seems to take a somewhat different approach for things like collections and loops.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: An example for love.graphics.getModes() ?

Post by rude »

I've updated the documentation to include this example. I hope that's okay, surtic.
surtic
Citizen
Posts: 74
Joined: Sat Jul 12, 2008 12:18 am

Re: An example for love.graphics.getModes() ?

Post by surtic »

Of course that's ok.

I'd be happy to write more examples and tutorials - where can I send them to? (Also, is there a concise list of wanted tutorials, something a bit shorter than the endless thread?)

For Lua tutorials, the first point of reference is the Lua website (http://www.lua.org) and the Lua wiki (http://lua-users.org/wiki/) which contains a few tutorials (http://lua-users.org/wiki/TutorialDirectory).
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: An example for love.graphics.getModes() ?

Post by rude »

@surtic:

Hmm, there aren't that many tutorial requests these days. I think we better stick to code examples in the documentation for now.
Post Reply

Who is online

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