-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Fix invalid frame
index when Sprite2D's hframes
or vframes
change
#85317
Fix invalid frame
index when Sprite2D's hframes
or vframes
change
#85317
Conversation
I think the fix is needed, but I would probably set it to the highest value instead. |
I though about that too. But I'm guesssing that in most use cases it just doesn't matter which new valid value is chosen, it is not exactly right for the user anyway. Let's say the user has a sprite sheet of 4 rows x 6 columns. Sprite currently uses the last frame (23). Then user decides that the last row is no more needed and changes the sheet to 3 rows x 6 columns. Most likely the new last frame (17) isn't any better choice for the sprite than the first frame. In my opinion the first frame is just a more intuitive default value when such a value is needed. My other guess is that most often this bug happens when user is editing sprites and sprite sheets in editor so the user immediately sees what's happening. Frame just resetting to 0 is maybe less startling than frame jumping from 23 to 17. |
Makes sense to me to handle this case indeed. Regarding what But that made me realize that this is a problem any time For example with the spreadsheet in the OP: If So maybe we should always reset Alternatively, we could try to calculate the would be |
I think always resetting (Red box represents the direction to where the user is expanding the texture.) Only changing
This would likely be the most elegant solution. |
0201ebe
to
d506d84
Compare
I changed how |
|
d506d84
to
000f2f1
Compare
I added same logic to
A separate PR exists for adding property change guards: #85311 |
000f2f1
to
45b7579
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me, but needs adjustments to the docs and comments.
45b7579
to
484c5b5
Compare
Adjustments done. |
Thanks! |
frame
index when Sprite2D's hframes
or vframes
has been changedframe
index when Sprite2D's hframes
or vframes
change
Cherry-picked for 4.2.2. |
This is my test sprite sheet:
In master this code causes an error as expected:
But this is fine:
Now the sprite looks very odd. The size and shape match to the spritesheet's current frame size and shape, but the content is garbage.
If the same is done in editor's property Inspector, the result is more or less the same. Editor however changes the
frame
property to 1, but still the sprite looks wrong.With this PR the sprite looks like this when the code above is run:
How
vframes
andhframes
changes can affectframe
What cases this PR handles and how. The goal is to make sure that the frame value keeps valid (must be smaller than
hframes * vframes
) and if possible, to keepframe
referencing the same row and column in the texture sheet even ifvframes
orhframes
changes.vframes
changes(a)
frame
's validity or value cannot change.(b)
frame
can become invalid, if its row is dropped.frame
's value cannot change.hframes
changesSpecial case where
vframes
is 1:(c)
frame
's validity or value cannot change.(d)
frame
can become invalid, if its column is dropped.frame
's value cannot change.When
vframes
> 1:(e)
frame
cannot become invalid, but its value can change.(f)
frame
can become invalid if its column is dropped, alsoframe
's value can change.if frame <= hframes * vframes
. If not,frame
is reset to 0.frame
to 0. Otherwise calculate original row and column and then calculate new frame value using newhframes
values. Finally theif frame <= hframes * vframes
check is done.