Layer Controllers - An easier method of layer movement!

Share and discuss custom LunaLua code and content packs for SMBX2.

Moderator: Userbase Moderators

MrDoubleA
Edward
Edward
Posts: 396
Joined: Mon Aug 20, 2018 7:02 am
Flair: How much munchers?

Layer Controllers - An easier method of layer movement!

Postby MrDoubleA » Tue Sep 02, 2025 10:39 am

I hate SMBX's layer movement enough that I rewrote it from scratch out of spite.

Image

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:
  • Image Straight line controllers - moves a layer back and forth in a straight line
  • Image Circular controllers - moves a layer around a circular path
  • Image Looping controllers - moves a layer in a straight line, teleporting back to the start when it reaches its goal
  • Image 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.

Nerdy details: show
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!

Pjerun
Shy Guy
Shy Guy
Posts: 9
Joined: Sat Jun 25, 2022 4:58 am
Flair: SMBX Enjoyer
Pronouns: any
Contact:

Re: Layer Controllers - An easier method of layer movement!

Postby Pjerun » Tue Sep 02, 2025 10:41 am

good job, MrDoubleA! Controller NPCs sound more pleasant to use than Vanilla's events, hah.

mariobrigade2018
Eerie
Eerie
Posts: 723
Joined: Wed May 24, 2023 7:00 pm
Flair: OK in coding who dreams of making a Mario game
Pronouns: he/him

Re: Layer Controllers - An easier method of layer movement!

Postby mariobrigade2018 » 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.

Pixelated_Perfection
Swooper
Swooper
Posts: 60
Joined: Fri Feb 25, 2022 1:23 pm
Flair: "Good News! I'm stupid." /ref
Pronouns: She/They

Re: Layer Controllers - An easier method of layer movement!

Postby Pixelated_Perfection » Tue Sep 02, 2025 11:35 am

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

Marioman2007
2025 Egg Hunter
2025 Egg Hunter
Posts: 547
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: Layer Controllers - An easier method of layer movement!

Postby Marioman2007 » Tue Sep 02, 2025 12:43 pm

The easing looks so cool!
You went an extra mile for that, thanks

Shaktool
2025 Egg Hunter
2025 Egg Hunter
Posts: 554
Joined: Thu Jul 25, 2024 5:34 am
Flair: zip zoom
Pronouns: male

Re: Layer Controllers - An easier method of layer movement!

Postby Shaktool » Tue Sep 02, 2025 12:45 pm

This needs to be in basegame

squp
Snifit
Snifit
Posts: 212
Joined: Sat Aug 12, 2017 10:10 pm
Flair: worm
Pronouns: she/it
Contact:

Re: Layer Controllers - An easier method of layer movement!

Postby squp » Tue Sep 02, 2025 1:51 pm

you are an actual hero

PizzaNoob
Swooper
Swooper
Posts: 69
Joined: Wed May 29, 2024 8:36 pm
Flair: I like to make comics!
Pronouns: he/him

Re: Layer Controllers - An easier method of layer movement!

Postby PizzaNoob » Tue Sep 02, 2025 2:03 pm

This is pretty awesome! It’s like an upgrade to your other script, simpleLayerMovement.lua

AdvancedTrash
Cheep-Cheep
Cheep-Cheep
Posts: 13
Joined: Fri Apr 25, 2025 4:21 pm
Pronouns: he/him

Re: Layer Controllers - An easier method of layer movement!

Postby AdvancedTrash » Tue Sep 02, 2025 2:52 pm

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
Image


Return to “LunaLua”

Who is online

Users browsing this forum: FutureNyanCat and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari