I see... Theoretically it should be possible to create such a position variable then, by simply changing the positions of the objects in the layer. In any case, it would be nice to see an example of how to correctly use the layer speed. At the moment, I'm making the assumption that the code is called once per frame, which is the ideal. It does appear, however, that frameskip might cause these events to be skipped, which breaks the cycle.Kevsoft wrote:Layers in SMBX don't have positions. They only move their objects by the speed, nothing else.
At the moment, I'm having to create a bounding box, which stops the motion and prevents the movement events from continuing if the player is outside it. This seems to work okay, but a more concrete solution would be preferred.
EDIT: Okay, this doesn't work 100% of the time, and the events can still get out of sync, but it's now extremely rare, which is good.
EDIT EDIT: Okay, I think I've improved it a little, but it's still not perfect. It seems that, very occasionally, LunaLua either skips frames (even while frameskip is turned off) or runs a frame twice. This makes looping movements essentially impossible to deal with, because LunaLua's update cycle doesn't match with the update cycle of layer movements. This means that any layer movement can move too much, or too little, causing errors in the movement. I hope there is some way this can be fixed in future versions. My suggestion would be to handle "layer movement" manually, rather than going through SMBX's system, and update the position of objects in the layer as SMBX does, but within the DLL. The benefit of this would be to guarantee that if a frame is skipped in Lua, then it will also skip frames in the layer movement (meaning that events to change movement speed won't be skipped). It will also making logging and setting absolute layer positions a possibility, which is a much more intuitive system for certain kinds of operation.
EDIT EDIT EDIT: AHA! I've worked it out! While the player is taking damage (or collecting a powerup), LunaLua remains updating. However, layer movement does not apply while this is happening. Because of this, the layer position desyncs from the counter. This causes layers to be in the wrong place, moving in the wrong direction. Is there a way to prevent this?