Page 1 of 1
Layer Controllers - An easier method of layer movement!
Posted: Tue Sep 02, 2025 10:39 am
by MrDoubleA
I hate SMBX's layer movement enough that I rewrote it from scratch out of spite.
Layers can be moved using
controller NPCs. Place one of them down near your layer, and you can customise its movement through extra settings. The following types of controllers are available:
Straight line controllers - moves a layer back and forth in a straight line
Circular controllers - moves a layer around a circular path
Looping controllers - moves a layer in a straight line, teleporting back to the start when it reaches its goal
Rotating controllers - orbits the objects in a layer around itself
Controllers will move the layer which they are placed on. They can also be set up to use easing functions to make their movement smoother, or to only begin moving when a specific event is triggered.
As a bonus, the layer movement from controllers should be much more performant than standard layer movement. This is because:
- It doesn't destroy the block lookup system as soon as a block moves horizontally. Instead, the lookup is just updated as needed.
- It doesn't search through every single object in the level once per layer, per frame. Instead, it keeps a cache of what objects exist on which layers.
- By default, controllers only move layers when close enough to being on camera.
The library is split into two parts:
layerControllers.lua and
layerMover.lua. layerMover.lua is what powers the more performant layer movement, and exists as a separate library so that other Lua scripts can take advantage of that. Example code for that:
Code: Select all
local layerMover = require("layerMover")
-- Creates a "layer mover" to be able to control a specific layer
local testMover = layerMover("test layer name")
function onTick()
if Layer.isPaused() then
-- Stops the movement of the layer, resetting the speed of everything on the layer
testMover:stop()
else
-- Moves the layer 2 pixels to the right each frame
testMover:translate(2,0)
end
end
Read through some of layerMover's comments to see more functions.
Also, if for whatever reason you need to update the aforementioned cache of objects, you can call layerMover.refreshLayerEntityMap().
Download!
Re: Layer Controllers - An easier method of layer movement!
Posted: Tue Sep 02, 2025 10:41 am
by Pjerun
good job, MrDoubleA! Controller NPCs sound more pleasant to use than Vanilla's events, hah.
Re: Layer Controllers - An easier method of layer movement!
Posted: Tue Sep 02, 2025 11:03 am
by mariobrigade2018
Yay new stuff to mess around with!
MrDoubleA wrote:I hate [this thing] enough that I rewrote it from scratch out of spite.
This is the origins of how I made some of my own stuff too lmao.
Re: Layer Controllers - An easier method of layer movement!
Posted: Tue Sep 02, 2025 11:35 am
by Pixelated_Perfection
mariobrigade2018 wrote: ↑Tue Sep 02, 2025 11:03 am
Yay new stuff to mess around with!
MrDoubleA wrote:I hate [this thing] enough that I rewrote it from scratch out of spite.
This is the origins of how I made some of my own stuff too lmao.
truly spite can be a universal motivator
Re: Layer Controllers - An easier method of layer movement!
Posted: Tue Sep 02, 2025 12:43 pm
by Marioman2007
The easing looks so cool!
You went an extra mile for that, thanks
Re: Layer Controllers - An easier method of layer movement!
Posted: Tue Sep 02, 2025 12:45 pm
by Shaktool
This needs to be in basegame
Re: Layer Controllers - An easier method of layer movement!
Posted: Tue Sep 02, 2025 1:51 pm
by squp
you are an actual hero
Re: Layer Controllers - An easier method of layer movement!
Posted: Tue Sep 02, 2025 2:03 pm
by PizzaNoob
This is pretty awesome! It’s like an upgrade to your other script, simpleLayerMovement.lua
Re: Layer Controllers - An easier method of layer movement!
Posted: Tue Sep 02, 2025 2:52 pm
by AdvancedTrash
This is extraordinary, and simplifies a lot. I was using simpleLayerMovement and it did well, and I'll have more time to mess around with it tomorrow, but when it comes to respawnRooms.lua, is there an appropriate argument that prevents events like these from happening? I'll be figuring out a way when I have some time tomorrow but I thought I'd ask in case something was already built in or obvious with resetting
