From PGE Wiki
Jump to: navigation, search

bgofix is an API that makes BGOs more customizable.


With this API, you can:

  • Make custom BGOs of any size,
  • Change the render priority of BGOs, and
  • Give BGOs custom animations


Download the API here and extract its contents in either your level's custom graphics folder for use in a level, along with a lunadll.lua file, or in the same directory as your .wld file along with a lunaworld.lua file for use throughout an entire episode.


To enable the bgofix library in a level, add this line to your 'lunadll.lua' file:

local bgofix = API.load ("bgofix");

Use PGE's GIFs2PNG utility to change the contents of your level's folder to PNGs. LunaLua does not support GIF images in its drawImage function.

BGOs of custom sizes will now automatically be rendered correctly at runtime.


  • It is not recommended to use this library to modify the width, height, render priorities, or number of frames that animated BGOs have. This has been known to cause bugs. Instead, make your own animated BGO over one that is not animated by default.
  • Using this library may result in slight changes in the render order of BGOs from normal. If this messes up the render priority, adjust the render priorities with setPriority.
  • The BGOs are only rendered correctly during SMBX runtime. In editing mode, they will still be shown in default size. For the most convenience, use the PGE editor as it can draw BGOs of any size natively.

Functions (Must be called in onStart)

setPriority id priority
Sets the render priority of the BGO nil int

The ID of the BGO


The LunaLua render priority.

setAnimation id numFrames frameSpeed
Sets the animation of the BGO nil int

The ID of the BGO


The number of frames. Defaults to 4 if not set.


How many ticks each frame of the animation will be displayed. Default = 8.

disableDraw id
(v1.0.1 +)

Disables drawing of the BGO

nil int

The ID of the BGO



setPriority uses LunaLua render priorities. These are not equivalent to SMBX sort order priorities! See here[1] for more information.


setAnimation may not work in the way you expect. Don't replace a BGO's image with an animated version as you would normally do in SMBX. Instead, do the following:

  1. Create a copy of the desired animated BGO image, then remove all but the first frame from that copy.
  2. Save the image with only the first frame as the "background-*.png" image. (Replace '*' with the ID)
  3. Save the image with all of the frames as "bgo-anim-*.png" (Replace '*' with the ID)

This may seem like a bit of a hassle, but it is less of a hassle than trying to edit a level with your custom animated BGOs showing all their frames at once, and since the way BGOs are drawn in PGE can't currently be changed, this was the only way to get around this problem.