Suggestion: Overlay.Flip

Started by ThreeOhFour, Wed 11/12/2024 02:04:20

Previous topic - Next topic

ThreeOhFour

Forgive me if this is already on the roadmap or already exists but I searched the forum, manual and autocomplete suggestions and couldn't find it!

It's very convenient to be able to rotate overlays without having to pass them through a dynamic sprite first, and it would be similarly useful to have an individual flip operation for overlays, similar to how the dynamic sprite flip works. Easy enough to work around by using a dynamic sprite, but having this functionality built in would be a nice little bonus.

eri0o

More a note for future person doing this, DynamicSprite.Flip supports horizontal, vertical and both as flip possibilities through an enum.

But views traditionally only flip horizontally. This is why in the current graphics drivers (D3D, OGL, Software) only the horizontal flip is implemented. If we want to support all directions of a DynamicSprite.Flip it would require supporting those directions at the graphics driver.

Crimson Wizard

#2
If "flip" is mirroring, then that may be achieved by setting negative scaling.

That should already work for GUI in AGS 4, but I don't remember by heart if that works for overlays.

EDIT: well, it's trivial to support negative width and height for overlays, but in current "Scaling" implementation in gfx drivers the negative scaling stretches textures to the opposite side of their origin. Meaning, the image shifts leftwards/topwards from "position".
GUI scaling has the same effect.
I recall having doubts about this, but since this is a new feature, I probably decided to leave this until there's user feedback.
https://github.com/adventuregamestudio/ags/pull/2426

The "flip" setting additionally fixes texture position to keep it where an unflipped texture would be.
Adding vertical flip to the graphic drivers is a non-issue.
But flip only potentially allows 3 scaling variants: (-1.0, 0), (0, -1.0) and (-1.0, -1.0).

Crimson Wizard

So, I suppose, there are two issues related to this.

Having distinct Flip property may be useful for users convenience, because mirroring is the most common effect that they want. Internally it may be converted to a negative scaling with sprite position adjustment.

But then, there's also a question if we want to have regular Scaling also have a fixed offset. Because that's likely expected by users in majority of cases too.

ThreeOhFour

That's a good point. The negative scaling is something I'm used to in some software - I hadn't thought to try it here. I also think that having a distinct Flip property is useful because the engine supports this behaviour in a limited way with ViewFrames and more extensively with DynamicSprites, and I can imagine it would not be uncommon to want to perform operations where you're checking if a ViewFrame is flipped and then flipping the overlay if so.

Crimson Wizard

I started working on Overlay.Flip, and ended up supporting full flip selection for the ViewFrame:
https://github.com/adventuregamestudio/ags/pull/2619
https://github.com/adventuregamestudio/ags/pull/2620

there are just a lot of things connected here, so when you begin changing one, you see that you can update others too.

ThreeOhFour

Superb, thank you so much. Being able to flip ViewFrame in the full range is also a fantastic idea.

Crimson Wizard

#7
The combined test build, if anyone like to try:
https://cirrus-ci.com/task/5407716887232512
WARNING: upgrades the game project to the new format, so don't use this on your real game project.
ViewFrames have a Flip property with 4 choices in the editor. The "Flip" command from menu ("F" key for shortcut) still flips only horizontally, I thought that would be convenient.
In script ViewFrame.Flipped was changed from boolean to eFlipDirection (since bool = 1 matches FlipHorizontal value).
Added Overlay.Flip property.

ThreeOhFour

This works perfectly, thank you!

One thing that I especially appreciate (and I wasn't sure if it would work, but it seems to be working perfectly - my memory of using enumerated types is so foggy!) is that I can inherit the flipped property like:

Code: ags
  PlayerView = Game.GetViewFrame(player.View, player.Loop, player.Frame);
  FlipSprite = DynamicSprite.CreateFromExistingSprite(PlayerView.Graphic);
  FlipSprite.Flip(PlayerView.Flipped);
  oFlipCopy.Graphic = FlipSprite.Graphic;

Which I love! Fantastic stuff.

SMF spam blocked by CleanTalk