Share and discuss custom LunaLua code and content packs for SMBX2.
Moderator: Userbase Moderators
|
|
|
|
-
MrDoubleA
- Edward

- Posts: 396
- Joined: Mon Aug 20, 2018 7:02 am
- Flair: How much munchers?
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.
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!
|
|
|
|
|
|
|
|
|
-
Pjerun
- Shy Guy

- Posts: 9
- Joined: Sat Jun 25, 2022 4:58 am
- Flair: SMBX Enjoyer
- Pronouns: any
-
Contact:
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

- Posts: 726
- Joined: Wed May 24, 2023 7:00 pm
- Flair: OK in coding who dreams of making a Mario game
- Pronouns: he/him
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

- Posts: 60
- Joined: Fri Feb 25, 2022 1:23 pm
- Flair: "Good News! I'm stupid." /ref
- Pronouns: She/They
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

- Posts: 547
- Joined: Tue Aug 25, 2020 3:19 am
- Flair: Dr. Bones
- Pronouns: He/Him
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

- Posts: 560
- Joined: Thu Jul 25, 2024 5:34 am
- Flair: zip zoom
- Pronouns: male
Postby Shaktool » Tue Sep 02, 2025 12:45 pm
This needs to be in basegame
|
|
|
|
|
|
|
|
|
-
squp
- Snifit

- Posts: 212
- Joined: Sat Aug 12, 2017 10:10 pm
- Flair: worm
- Pronouns: she/it
-
Contact:
Postby squp » Tue Sep 02, 2025 1:51 pm
you are an actual hero
|
|
|
|
|
|
|
|
|
-
PizzaNoob
- Swooper

- Posts: 75
- Joined: Wed May 29, 2024 8:36 pm
- Flair: I like to make comics!
- Pronouns: he/him
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

- Posts: 13
- Joined: Fri Apr 25, 2025 4:21 pm
- Pronouns: he/him
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

|
|
|
|
|
|
|
|
|
-
Alucard648
- Flurry

- Posts: 182
- Joined: Sun Aug 16, 2015 3:45 am
Postby Alucard648 » Thu Sep 04, 2025 8:11 pm
This looks quite promising, but here are a couple of questions:
1. Does those layer controller NPCS work when offscreen? Otherwise they despawn, causing layer to stop moving, and thus wrecking level design.
2. Does the incremental layer movement controller play sound per step, just like incremental scroll in Castlevania 3?
3. Does the layer movement work with NPCS?
|
|
|
|
|
|
|
|
|
-
marioSuper21
- Hoopster

- Posts: 44
- Joined: Thu Jul 31, 2025 8:43 am
- Pronouns: he
Postby marioSuper21 » Fri Sep 05, 2025 10:25 am
Alucard648 wrote:
This looks quite promising, but here are a couple of questions:
1. Does those layer controller NPCS work when offscreen? Otherwise they despawn, causing layer to stop moving, and thus wrecking level design.
2. Does the incremental layer movement controller play sound per step, just like incremental scroll in Castlevania 3?
3. Does the layer movement work with NPCS?
1. I haven't tried it yet but it's likely to happen.
2. If the code supports it.
3. I see in the GIF that the NPCs are moving.
AdvancedTrash wrote:
|
|
|
|
|
|
|
|
|
-
FutureNyanCat
- Foo

- Posts: 808
- Joined: Fri Dec 20, 2013 8:39 pm
- Flair: Species: Felis robotus
- Pronouns: He/Him
-
Contact:
Postby FutureNyanCat » Fri Sep 05, 2025 10:42 am
Alucard648 wrote: ↑Thu Sep 04, 2025 8:11 pm
1. Does those layer controller NPCS work when offscreen? Otherwise they despawn, causing layer to stop moving, and thus wrecking level design.
I've tested this by putting a layer controller NPC outside of the level boundaries in a level I'm working on for my project, and yes, I can confirm they can work off-screen. However, if you want them to stop working unless the controller NPC is on-screen, just switch Activation Mode to Active Within Range and set the Activation Margin to 0.
|
|
|
|
|
Return to “LunaLua”
|