MenuItemImage how to add sound effect when button clicked in and when clicked out?

MenuItemImage how to add sound effect when button clicked in and when clicked out?
0

Hello,
I have the following code:

auto startButton = MenuItemImage :: create (“button.png”, “button_clicked.png”, CC_CALLBACK_1 (MainScene :: goToGameScene, this));

I want when I press the button starts to sound and then I released the button starts to other sound.

How can I do that?

you need to use ui::button for that, it provides listeners for touch began,ended and move.

Yes, I know this, but I wonder how it can be done with MenuItemImage…

I dont think it can be done with menuitemimage.

It’s not quite what MenuItemImage is for you can play a single sound, but capturing the click up event isn’t there.

You could simulate it, maybe, play your down sound first, run your logic, then play your "up’ sound.

ui::button or use a Sprite with begin and end listeners.

Yes, that’s what I’m doing right now, but I wondered if there was a way to do it like a button. Thanks for the answers.