Resizing a NineSliceSprite after creation does not work properly when using Animated sprite
See original GitHub issueOS platform / Browser
Windows 10, Chrome 105
melonJS version
v13.0.0
Bug description
The NineSliceSprite
internal properties nss_width
and nss_height
never gets updated, making it impossible to change the NineSliceSprite size.
Setting the (undocumented) properties nss_width
/nss_height
instead of width
/height
seems to work, even if the sprite is animated.
I tried to patch the NineSliceSprite
class with something like this:
get width() { return super.width; }
set width(value) {
super.width = value
this.nss_width = value;
}
But every frame calls the Sprite.setRegion
method, which resets the width/height of the sprite
I 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, but resize()
is already taken by Rect
.
Furthermore, it would create even more confusion when trying to set the width
/height
properties directly (why resize()
works but width
/height
doesn’t?)
The ideal solution is to properly fix the get
/set
width
/height
behaviour.
Steps to reproduce the bug
// Create NineSliceSprite with size 32x32
const sprite = new NineSliceSprite(0, 0, {
image: 'nineslice',
width: 32,
height: 32
})
// Change width/height
sprite.width = 128
// NineSliceSprite don't change size
game.world.addChild(sprite)
Issue Analytics
- State:
- Created a year ago
- Comments:9 (7 by maintainers)
Top GitHub Comments
13.1.0 was just released ! Followed by a quick 13.1.1 fix but just for date and change tracking 😃
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
I’m afraid I have nothing better to offer for now, as I know you are on a tight schedule with the game jam !