rexrainbow / phaser3-rex-notes

Notes of phaser3 engine
MIT License
1.21k stars 263 forks source link

How to change (base)frame on PointerDown on ninepatch2 #400

Closed hashg closed 7 months ago

hashg commented 7 months ago

I want to change frame onPointerDown on ninepatch2 image which is pulled from atlas.

https://codepen.io/Harish-Gowda/pen/QWoZaeV

In this example (from -https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/assets/images/ninepatch/atlas.json) On load (baseFrame) - button_coral_s_b_slice9 On Pointer down (setBaseTexture) - button_green_s_b_slice9

It fails with following console log - Texture "__MISSING" has no frame "button_green_s_b_slice9"

rexrainbow commented 7 months ago

Change 'key' in line 28 ( button.setBaseTexture('key',... ) to 'atlas'. There has no key named 'key' in this test code.

hashg commented 7 months ago

Thanks for directing my focus to key.

https://codepen.io/Harish-Gowda/pen/QWoZaeV I have updated my codepen to show actual issue, when I try to use ninepatch inside a container class and then use same PointerEvent functions. It throws these errors - Texture "__DEFAULT" has no frame "button_green_s_b_slice9" Texture "__DEFAULT" has no frame "button_coral_s_b_slice9"

I plan to build two more class extended from BaseButton where in it will include a image (ImageButton) and text (TextButton). Is my approach right?

rexrainbow commented 7 months ago

this.texture in line 30,34 is undefined. Please check your logic/vairables first.