Valheim-Modding/Jotunn

[BUG] Sprites loaded from PNGs have a different pivot from those built into the game

joeyparrish opened this issue · 4 comments

Details:
Jotunn Version: 2.3.10
Jotunn Submodule(if applicable): AssetUtils
Repeatability(Consistent(100%), Inconsistent(50%), Rare(1%), Unknown(==1)): 100%

Problem Description:
I'm not entirely sure if "bug" is accurate...

I'm loading some custom Sprites from PNGs and compositing them with some Sprites that are built into the game. However, the different pivot points are causing me trouble. AssetUtils gives me a pivot of (0, 0), whereas the built-in Sprites for ItemDrop icons have a pivot of (0.5, 0.5).

After trying in vain to adjust the pivots after loading (probably my mistake somewhere), I found that modifying Jotunn to set the pivot to the center solved all my issues.

Suggestion:
I would like to either default the pivot to center in AssetUtils, or if there are backward compatibility concerns, add an argument to set the pivot with a default value set to the current pivot (Vector2.zero).

I have this working locally, and can send a PR if one of the suggestions above sounds good. If you prefer another solution, or if this is just something I need to learn to fix in my mod outside AssetUtils, please let me know.

Hey,

sorry, I was kind of cramped with other Jötunn stuff. I guess there are no side effects of having the pivot at (0.5,0.5)? I can test this with my mod compat setup and if it does no harm, I will add it to the AssetUtils for the next release.

It's hard for me to say if there are no side-effects. I am not testing my mod in combination with any other mods, and I'm not deeply familiar with the community.

A completely safe change would be to add an argument for the pivot, and default it to (0,0). Then I could explicitly ask for (0.5,0.5) in my mod.

I'm happy to throw together a PR for either solution if you like.

Oh, yeah. Making it a parameter seems like the best way. If you want, i will take the PR. But please make an overload for it or else the signature of the method changes and all mods using it have to recompile.

Ah, okay. I didn't know that. Can do!