This library is neat and I've used it a lot. I suddenly came up with an incompatibility with another module and since I've nutted it out, I thought i would post here.
When lovelytoast draws a toast message, it correctly takes
Code: Select all
love.graphics.getWidth()
I then used this library with a auto-screen resizer thingy that scales all drawing events to new monitor/desktop sizes. The one I use is tlfres.lua. It's an oldie but goodie. tlfres was printing the toast message left-of-centre and I couldn't work out why but I got it eventually.
If I 'code' for a window that is 1920 wide but is actually displayed on a screen that is 1440 wide then tlfres will automatically scale everything by 0.75 (1440/1920 = 0.75) in a way that is transparent to the coder (me) so I don't even need to think about this. An unexpected consequence:
- I code my game assuming 1920
- I invoke lovelytoast
- lovelytoast 'grabs' the real monitor size (1440)
- lovelytoasts draws in the centre of the screen (x = 720)
- tlsfres then scales that by 0.75
- the toast message now appears x = 540 which is left of centre
To be clear, this isn't the fault of lovelytoasts. Just an unexpected incompatibility.
My solution:
I don't let lovelytoasts grab the real screensize. Instead I feed in (via parameter) the screensize it needs to pretend and work with. In my case, I tell LT to pretend the screen width is 1920:
- I code my game to screen width 1920
- invoke LT and tell it to pretend screen width is 1920
- LT draws centre of 1920 (960)
- tlsfres then scales that by 0.75 (720)
The toast message is now correctly centred (noting I'm ignoring the width of the text and font for simplicity).
I modified the LT library to accept another optional parameter - the assumed width of the screen:
lovelyToasts.show("This is a toast message", 3, nil, 1920)
1920 is the assumed width of the screen. Sorry for all the text. It took me ages to work it out so thought this might help others.
Modified library attached.