-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How should Gum handle circular dependencies between size and texture addresses? #396
Comments
I agree with profexorgeek (Item 1 below) (These numbers are not aligned with your numbers)
The rest of these are me tossing out thoughts: |
After thinking through this, I have a solution that I really like. When Gum sees this circular reference, it could completely ignore Texture Width and instead base the width of the Sprite on the dimensions of the source PNG file (ignoring the Texture Width value). This has the following benefits:
Of course, this would be considered a breaking change, and will be mentioned as such in the next release, but I think it's worth doing since it was previously an undefined behavior caused by circular dependencies. Also it's worth noting that Gum does allow circular dependencies in lots of other cases, such as parent/child relationships. These types of relationships are encouraged in many cases and well defined, so this new proposal is not a philosophical break from how Gum normally works. |
It turns out that the way I had it described is how I had already implemented it - I just didn't remember. At least now it's also documented: https://docs.flatredball.com/gum/readme/gum-elements/sprite/texture-address#dimensionsbased |
Summary
It is possible to have a Sprite where the width of the sprite depends on the texture coordinates, but the texture coordinates depend on width. How should Gum solve this problem. For brevity this topic only mentions width, although the same concepts apply to height.
Details
When working with sprites, the two most common setups are to have the width depend on texture coordinate (1) and to have the texture coordinate depend on the width (2).
1. Width Depends on Texture Coordinates
This is the most common setup for Sprites. This setup has:
With this setup, the calculation for width is:
AbsoluteWidth = Width * Texture Width
Texture Width is a hard value that you can specify in the editor.
So if a sprite is using a source file that is 256 pixels wide, and its Width is 100, then the absolute width of the sprite is 256:
If you change the texture coordinates, then the absolute width of the sprite changes too
This is the most common setup because it lets users select regions from a sprite sheet (or animations in an AnimationChain) and the sprite always adjusts appropriately.
2. Texture Coordinates Depend on Width
This setup is not very common, but it can be used for things like health bars, effects where sprites are gradually revealed, and filling progress bars.
This setup has:
With this setup, the calculation for width (assuming Absolute Width Units) is:
AbsoluteWidth = Width
But in this case Texture Width is calculated like this:
TextureWidth = AbsoluteWidth
If you change the absolute width of the sprite (by changing its Width value), then the TextureWidth value adjusts in response.
Absolute Width and Texture Width depend on each other
It is possible to mix the two situations above by setting these values:
This creates a circular dependency which currently Gum resolves somewhat arbitrarily. In fact, I'm actually not 100% sure exactly how it is resolved and I don't know if it's worth researching the code to figure this out. All I know is that it "works" in that it doesn't cause infinite recursion, and the Sprites do not completely blow up or shrink to 0 width. It is at least stable.
When this happens, what should Gum do? Here are some options I've come up with to get the conversation started:
Please let me know your thoughts.
The text was updated successfully, but these errors were encountered: