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

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
Sambo
Snifit
Snifit
Posts: 211
Joined: Fri Jan 24, 2014 6:43 pm

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

Postby Sambo » Sat Nov 12, 2016 11:08 pm

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.
Last edited by Sambo on Mon Mar 20, 2017 5:14 pm, edited 3 times in total.

loop
Ninji
Ninji
Posts: 984
Joined: Sun Apr 17, 2016 5:56 pm
Flair: i may be dumb but im not stupid!
Pronouns: he/him/they

Re: Better Custom BGOs

Postby loop » Sun Nov 13, 2016 9:51 am

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.

Sambo
Snifit
Snifit
Posts: 211
Joined: Fri Jan 24, 2014 6:43 pm

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

Postby Sambo » Thu Nov 17, 2016 10:46 pm

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.

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9891
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

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

Postby Emral » Fri Nov 18, 2016 6:13 am

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.

Sambo
Snifit
Snifit
Posts: 211
Joined: Fri Jan 24, 2014 6:43 pm

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

Postby Sambo » Fri Nov 18, 2016 11:04 pm

That makes sense. But it's pretty hard to manipulate the render order with the sort priority system.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

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

Postby Hoeloe » Sat Nov 19, 2016 4:33 am

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.

Sambo
Snifit
Snifit
Posts: 211
Joined: Fri Jan 24, 2014 6:43 pm

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

Postby Sambo » Mon Nov 21, 2016 7:27 pm

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.

Sambo
Snifit
Snifit
Posts: 211
Joined: Fri Jan 24, 2014 6:43 pm

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

Postby Sambo » Mon Dec 26, 2016 6:02 pm

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.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari