-
-
Notifications
You must be signed in to change notification settings - Fork 642
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
Resizing a NineSliceSprite after creation does not work properly when using Animated sprite #1115
Comments
oh boy, I could swear this one was working ! I'll fix it anyway and add a corresponding test unit to prevent breaking it again if this is/was a regression. Thanks for reporting it 👍 |
actually just setting the private |
adding the following getter/setter to the NineSliceSprite class seems to do the trick on my side : /**
* width of the NineSliceSprite
* @public
* @type {number}
* @name width
*/
get width() {
return super.width;
}
set width(value) {
super.width = this.nss_width = value;
}
/**
* height of the NineSliceSprite
* @public
* @type {number}
* @name height
*/
get height() {
return super.height;
}
set height(value) {
super.height = this.nss_height = value;
} however I do not have any animated example for dialog box, so if you could also kindly confirm it's working on your side it would be great ! if it works I'll push those changes to the master branch, if not can you maybe share a minimal example here I can reuse for debugging? |
I committed the changes, maybe easier to pull the latest changes on your side : let me know, once you confirm you are good with it I'll publish the 13.1 version. thanks again! |
Sadly the fix wasn't enough. melonJS/src/renderable/sprite.js Lines 460 to 461 in 709d217
Here is a sample that reproduces the issue: https://github.com/NemoStein/melonjs-9slice-sample |
oh I see...... honestly I don't know how to fix this one quickly... the thing is that the sprite resizing/scaling feature rely on Matrix transformation to display the final sprite "size" and if you look at the Sprite Class code we actually never change the size of the sprite. So I really need to think about this one... a quick and dirty fix is certainly to override the update method, call the update(dt) {
// .... do your stuff
var dirty = super.update(dt);
if (dirty) {
// most likely the sprite frame was changed
// Change width/height
sprite.width = sprite.nss_width = 128;
}
return dirty;
} I'm afraid I have nothing better to offer for now, as I know you are on a tight schedule with the game jam ! |
Don't worry, I'll keep using the It's just a progress loading bar, after all! ;D |
ok, I'll keep it like this for now and go on with the 13.1 release. I will see later how we can properly implement this. I must admit though I never thought about using a 9-slice sprite for a loading bar :) |
13.1.0 was just released ! Followed by a quick 13.1.1 fix but just for date and change tracking :) |
OS platform / Browser
Windows 10, Chrome 105
melonJS version
v13.0.0
Bug description
The
NineSliceSprite
internal propertiesnss_width
andnss_height
never gets updated, making it impossible to change the NineSliceSprite size.Setting the (undocumented) properties
nss_width
/nss_height
instead ofwidth
/height
seems to work, even if the sprite is animated.I tried to patch the
NineSliceSprite
class with something like this:But every frame calls the
Sprite.setRegion
method, which resets the width/height of the spriteI think the easiest (but far from ideal) approach is a new method
NineSliceSprite.changeSize(w, h)
(or something like this)NineSliceSprite.resize
can be used, butresize()
is already taken byRect
.Furthermore, it would create even more confusion when trying to set the
width
/height
properties directly (whyresize()
works butwidth
/height
doesn't?)The ideal solution is to properly fix the
get
/set
width
/height
behaviour.Steps to reproduce the bug
The text was updated successfully, but these errors were encountered: