Page 1 of 1

Better Custom BGOs with bgofix.lua (Added wiki page)

Posted: Sat Nov 12, 2016 11:08 pm
by Sambo
When you make custom BGOs, your options are limited. They all have to be the same size as the originals, and you can't change the order in which they are rendered. I have created an API which allows for more customization with BGOs. It allows you to change their size and render order. It even allows you to give them custom animations! Using it is simple.

Wohlsoft.ru Wiki Page

Call the API with:

Code: Select all

local bgofix = API.load
If you just wanted to change the size of some BGOs, this is all you need to do. It will correctly display BGOs of custom sizes automatically.
To change the render order, just call this function in onStart:

Code: Select all

bgofix.setPriority(id, priority)
id is the ID of the BGO.
priority is the LunaLua render priority, NOT the SMBX sort priority. You can find more information here.
To change a BGO's animation, call:

Code: Select all

bgofix.setAnimation(id, numFrames, frameSpeed)
id is, again, the ID of the BGO.
numFrames = the number of frames
frameSpeed = the frame speed in SMBX ticks per frame. If not defined, it is set to 8 by default.
To set an animation, you must create an image of all the frames, in the same style as all the other animated images in SMBX, with the naming convention, "bgo-anim-*.png," where '*' is the ID.
For the regular "background-*" custom image, just make an image of the first frame. This is so it won't look screwy in the PGE editor.

This API will also serve as a temporary fix for the bug with lunaTester that makes BGOs with smaller custom images than the originals to look screwy.
Download: https://www.dropbox.com/s/v3aaet4ij4wd3 ... x.zip?dl=1
To install, just drop the contents of the zip into your luaScriptsLib folder.

Notes. Please read before you complain about the API not working:
  • The custom BGO images must be in .PNG format for this API to work, because LunaLua's drawImage function doesn't support drawing of masked GIFs.
  • If you make an animated background of a custom size, it won't be displayed correctly unless you use the setAnimation function.
  • This API uses LunaLua render priorities when drawing BGOs. The custom BGOs should render in about the same order as they do normally, but slight changes may occur. If this happens, just use setPriority to fix it.
  • If you try to use this with the legacy SMBX editor, you're gonna have a bad time, because they will still be the original size. Use Wohl's editor.
If you find any bugs, please report them so I can fix them.

Re: Better Custom BGOs

Posted: Sun Nov 13, 2016 9:51 am
by loop
So, if we put the priority at -20.0, it will be rendered in the foreground?
That's my only question.
Anyway, this API sounds really useful. If I figure out how it works, I might use this.

Re: Better Custom BGOs with bgofix.lua (Added wiki page)

Posted: Thu Nov 17, 2016 10:46 pm
by Sambo
Jayce 777 wrote:So, if we put the priority at -20.0, it will be rendered in the foreground?
Is that what the LunaLua render priority table says? It seems pretty self-explanatory to me.
(But yeah, that's correct.)

I just added a wiki page on wohlsoft.ru.
See it here.

I also made a small update with improved error handling. The provided download link will always have the latest version.

Re: Better Custom BGOs with bgofix.lua (Added wiki page)

Posted: Fri Nov 18, 2016 6:13 am
by Emral
The render priority thing you say in the intro is only half-true. More recently placed objects will always go in front of older objects when they have the same priority in vanilla. You might've not noticed that because in the old 1.3 editor there was a bug where it would save the level wrong.

Re: Better Custom BGOs with bgofix.lua (Added wiki page)

Posted: Fri Nov 18, 2016 11:04 pm
by Sambo
That makes sense. But it's pretty hard to manipulate the render order with the sort priority system.

Re: Better Custom BGOs with bgofix.lua (Added wiki page)

Posted: Sat Nov 19, 2016 4:33 am
by Hoeloe
Sambo wrote:That makes sense. But it's pretty hard to manipulate the render order with the sort priority system.
Uhh.... how is it hard? Bigger number renders on top of smaller number. The numbers are continuous, so -49.9 will render on top of -50. There's literally no way it could be simpler.

If your issue is two overlapping BGOs of the same type... there's not really a clean way to resolve that regardless of the system used.

Re: Better Custom BGOs with bgofix.lua (Added wiki page)

Posted: Mon Nov 21, 2016 7:27 pm
by Sambo
I know how the sort order priority works. What I'm saying is that changing the order in which backgrounds are rendered using that system is a pain. You have to place them in a certain order if they have the same priority, or you have to manually change the sort order priority every time you save the level.

Re: Better Custom BGOs with bgofix.lua (Added wiki page)

Posted: Mon Dec 26, 2016 6:02 pm
by Sambo
I just finished a couple of minor improvements to this API.

Changelog:

Code: Select all

1.0.1

-Added an option to disable the drawing of certain BGOs.
-Fixed a bug where all animated BGOs were being resized to the height of their custom images, making them taller than they were supposed to be.
-General optimizations

1.0.0

-Orignal Release
The download link has been updated.