malware-dev/MDK-SE

[DOCUMENTATION] Sprite Offset calculation wrong.

UbioZur opened this issue · 6 comments

In the documentation (thank you for it), the viewport calculation seem to be wrong for the sprite offset.

_viewport = new RectangleF(
        (_drawingSurface.TextureSize - _drawingSurface.SurfaceSize) / 2f,
        _drawingSurface.SurfaceSize
    );

This would center vertically and horizontally the viewport on the texture.

Except for vertical screens (The Programmable block main display for example), the viewport is not horizontally centered, it is aligned to the left (X=0).

It seems (but I haven't checked on all possible screens yet), that the viewport only center on the vertical axis.

the code would then be:

_viewport = new RectangleF( 0f, (_drawingSurface.TextureSize.Y - _drawingSurface.SurfaceSize.Y) / 2f,
        _drawingSurface.SurfaceSize.X, _drawingSurface.SurfaceSize.Y
    );

or

_viewport = new RectangleF( 
        new Vector2F (0f, (_drawingSurface.TextureSize.Y - _drawingSurface.SurfaceSize.Y) / 2f),
        _drawingSurface.SurfaceSize
    );

It's not big, but since your doc is an essential tool to reference when getting into SE scripting, I thought I would be nice to make sure the example codes works on as many situations as possible.

PS: I couldn't figure out where the source for the doc is to try to make is a pull request.

No, this is correct. It just so happens that most screens have Texture width = Surface width.

No, this is correct. It just so happens that most screens have Texture width = Surface width.

Most is not all and it is not correct since the code does not work for that particular screen.
Again the Automation Programable block main display (I did forgot to write automation on the initial post)

The main display width is 409.6 pixel, and is stating at an X of 0 and not 51.2 pixel.
It is so far the only vertical display I have found but checking every single blocks one at a time does take time.

As I said it's not big, just wanted to actually share that information in case some new scripter get stuck on why that display is working like the others.

Sounds like they've messed up the definition of that programmable block, then, that's interesting.
I have inside information on these things.

I'll try to remember to check up whether they've made a change in policy or whether it actually is wrong. I'll need to get into a situation where I have the ability to test these things myself first though.

Particularily because if it's not centered both ways, there really is no reason to make it harder on us and use the centering in the first place.

So strange behaviour, I restarted the game and now the viewport is centered.

So considering what you said that it is a policy for it to be centered, I must have encountered a very strange bug (probably in my script), and reloading must have fixed something.

So I will close the bug and keep an eye on it in case it happen again.

Thank you for letting me know, this got me really curious and as I said I'm not in a position to test yet :D