airstruck / luigi

Lovely User Interfaces for Game Inventors
MIT License
114 stars 23 forks source link

Usage for custom framework with letterboxing #52

Closed MikuAuahDark closed 7 years ago

MikuAuahDark commented 7 years ago

I'd like to use LUIGI for my game, but it uses framework which has letterboxing, so it has these restrictions:

airstruck commented 7 years ago

No call should be made to love.graphics.reset and love.graphics.origin. Additionally, graphics state must be balanced!

This should already be the case. If not it's a bug, please report it.

love.mousepressed, love.mousereleased, love.mousemoved, love.<more handles> shouldn't be overridden. It's substitute is available, and additionally for mouse/touch events, handles the coordinates because letterboxing.

These event handlers are set up when you "show" a layout using the Love backend (in backend/love.lua). It sounds like you need your own custom backend, mostly identical to the Love backend except that the "show" function uses your substitute event handlers rather than Love's.

You can simply overwrite the Love backend's "show" function somewhere in your own code. Anything else you may need to change for your letterbox backend should be in that same file, for example getWindowSize, maybe.

Touch events and mouse events are same.

This shouldn't be hard to add. It would go in that same "show" function.


I accidentally edited your question instead of replying, and your first paragraph is lost now. Sorry about that.

MikuAuahDark commented 7 years ago

Alright, I see..

One more question: How can I pass additional data to the backend? My framework is namespaced and isn't stored in global variable.

airstruck commented 7 years ago

You should be able to overwrite backend functions from someplace that has access to your letterbox framework (e.g. in your replacement functions, have letterbox module available as an upvalue).

local backend = require 'luigi.backend.love'
local letterbox = require 'mystuff.letterbox'

backend.getWindowSize = function ()
    return letterbox.geScreenWidth(), letterbox.getScreenHeight()
end
MikuAuahDark commented 7 years ago

Sorry, but I mean they even not loaded as requirerather than with love.filesystem.load.

But I get the idea, thank you very much.