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!