[BUG][PLAYER-EDITOR] Flipped hatches are offset incorrectly

Started by WillLem, January 18, 2025, 10:07:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

WillLem

I thought I'd already posted about this, but must've deleted it. Note that this bug is also present in NeoLemmix, but will probably not be fixed in CE (if CE ever happens) due to the very high potential for level breakage.

Basically, if a hatch's base .png image has an uneven amount of blank space either side of its widest filled pixels, it will be offset by the difference when opening the level in the Player. It will appear in the correct place in the Editor after flipping, but a quick glance at the level file will show that its X-position is actually off by (<> 0px).

A good example is the l2_beach hatch, which gets offset to the left by a whopping 5px:

--->
Left - how it appears in the Editor | Right - what's actually rendered in the Player

The simplest answer is to calculate this offset and add an extra line to flipped hatches in the level file (FLIP_X_OFFSET):


Note the incorrect "X" value of the flipped object.

The Player then uses this offset value to correct the position of the hatch.

Since this bug has gone unnoticed for so long (it's present as far back as NeoLemmix 12.9.2, possibly even earlier), I wondered whether it would even be worth fixing (probably why the original topic is missing), but it was such an easy and obvious fix that I deemed it at least appropriate for SLX, where any new content can now rely on the corrected hatch positions.

I did consider handling everything Player-side (so, no extra line in the level file), but it's actually easier to calculate the Offset value Editor-side; it's done by analysing the image and returning the blank margins, then comparing the difference to get the offset. Since the image is already loaded and selected at the point of being flipped, it makes sense to grab these values at this exact point. Attempting to do the same in the player would require unreasonable image accessing & analyzing gymnastics at some point well before the images are actually loaded for rendering. I suppose it could be done at the point the image is drawn, but that would involve implementing much deeper logic that allows the incorrect value to persist right to the wire: let's handle it before it gets that far.

I also think it makes sense to display the value somewhere that the designer can see what's happening (i.e. the flipped hatch actually does move X number of pixels to the left or right and this can be seen in the level file; the presence of the "FLIP_X_OFFSET" line is, therefore, obviously and observably correcting this).

Besides, it is in fact a bug that arises from a necessary part of the Editor's image processing (i.e. to flip it in-place, it needs to take blank space into account and move it accordingly; the Player should then follow suit, which it now does).

Fixed in Player commit ca5726a and Editor commit 601c7fe.