# Sprites, Button Images and Callback Actions

**URL:** <https://forum.babylonjs.com/t/sprites-button-images-and-callback-actions/45503>\
**Category:** Questions\
**Created:** [November 6, 2023, 11:19pm UTC](https://forum.babylonjs.com/t/sprites-button-images-and-callback-actions/45503 "2023-11-06T23:19:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdotpup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pdotpup/32/37958_2.png) [@pdotpup](https://forum.babylonjs.com/u/pdotpup)\
**Post date:** [November 6, 2023, 11:19pm UTC](https://forum.babylonjs.com/t/sprites-button-images-and-callback-actions/45503/1 "2023-11-06T23:19:35Z")

</div>

I’ve been studying the following example but I have 2 problems that I can’t seem to solve:

> **[Babylon.js Playground](https://playground.babylonjs.com/#7LHR3R%239)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Question 1) the images on each button/sprite don’t work. I tested several .png files but the checkerboard remains with each image, and it’s covered with a semi-transparent white shade. Perhaps it’s an image scaling issue, but then why is the checkerboard still visible behind the image? Even better, is there a way to make the entire SPRITE an image? Like this playground? [https://www.babylonjs-playground.com/#XCPP9Y#3281](https://www.babylonjs-playground.com/#XCPP9Y#3281)

Question 2) trying to pinpoint the BUTTON name or SPRITE name, so I can control the action in the onPointerDown callback. I’ve used the following format before to catch actions (see line #104 in playground above)

this usually works —\> (pickinfo.pickedMesh.name == “button6”) or (pickinfo.pickedMesh.name == “b6”)

but it’s not working in this example above. How can I access the sprite/button and catch the action in the onPointerDown callback? The material line seems to work fine in the example…

thanks in advance for any solutions

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [November 7, 2023, 3:58am UTC](https://forum.babylonjs.com/t/sprites-button-images-and-callback-actions/45503/2 "2023-11-07T03:58:06Z")

</div>

> the images on each button/sprite don’t work

They’re all 404 in the console for that playground, so I’m not sure what you’re seeing that makes them semi-transparent. I updated your playground to use the ‘textures/player.png’ sprite provided by the playground server and it looks correct.

> is there a way to make the entire SPRITE an image? Like this playground? [https://www.babylonjs-playground.com/#XCPP9Y#3281](https://www.babylonjs-playground.com/#XCPP9Y#3281)

I’m not sure what you’re asking for here. Maybe you’re asking how to use the `BABYLON.GUI.Button.CreateImageButton` function with a sprite? This might help: [How to import Textures and Images from a sprite sheet? - #7 by earthendev](https://forum.babylonjs.com/t/how-to-import-textures-and-images-from-a-sprite-sheet/10129/7)

> Question 2) trying to pinpoint the BUTTON name or SPRITE name, so I can control the action in the onPointerDown callback. I’ve used the following format before to catch actions (see line #104 in playground above)
> 
> this usually works —\> (pickinfo.pickedMesh.name == “button6”) or (pickinfo.pick\> edMesh.name == “b6”)
> 
> but it’s not working in this example above. How can I access the sprite/button and catch the action in the onPointerDown callback? The material line seems to work fine in the example…

There is a different function for sprite picking. See:  
[Picking Sprites | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/features/featuresDeepDive/sprites/picking_sprites).

I updated your playground to show it:  
[my menu | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#7LHR3R#18).

Does that help?

---

<div class="post-metadata">

**Author:** ![pdotpup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pdotpup/32/37958_2.png) [@pdotpup](https://forum.babylonjs.com/u/pdotpup)\
**Post date:** [November 7, 2023, 9:53am UTC](https://forum.babylonjs.com/t/sprites-button-images-and-callback-actions/45503/3 "2023-11-07T09:53:44Z")

</div>

Thank you, that is great! It seems that the sprite element overrides the button in this example. I thought it was the reverse. Final question then - How can I clear the entire structure?  
is it something like this ? ```

spritemanager.getChildren().forEach ((element) =\> element.setEnabled(false))

```auto

```

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [November 7, 2023, 11:52am UTC](https://forum.babylonjs.com/t/sprites-button-images-and-callback-actions/45503/4 "2023-11-07T11:52:47Z")

</div>

You want to clear them definitely, or just make them invisible? If you want to clear definitely, you can use `spriteManager.dispose()`. If it’s just to make them invisible, you can set `isVisible = false` on each sprite.

---

<div class="post-metadata">

**Author:** ![pdotpup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pdotpup/32/37958_2.png) [@pdotpup](https://forum.babylonjs.com/u/pdotpup)\
**Post date:** [November 7, 2023, 7:36pm UTC](https://forum.babylonjs.com/t/sprites-button-images-and-callback-actions/45503/5 "2023-11-07T19:36:20Z")

</div>

Hi - i want to toggle the visibility so I can open or close the menu on-demand. Turns out the solution was to access the sprite array AND meshes in the following way. Solution is unique to this particular playground:

```
                    1) meshGroup.forEach ((element) => element.setEnabled(false));
                    2) sprites.forEach ((element) => element.isVisible = false);
                    3) torus.isVisible = false;

```

Thanks!

---

<div class="post-metadata">

**Author:** ![pdotpup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pdotpup/32/37958_2.png) [@pdotpup](https://forum.babylonjs.com/u/pdotpup)\
**Post date:** [November 12, 2023, 12:17am UTC](https://forum.babylonjs.com/t/sprites-button-images-and-callback-actions/45503/6 "2023-11-12T00:17:30Z")

</div>

removed
