spinnerbox Posted April 12, 2015 Share Posted April 12, 2015 Is there a way to add a down sound on a Sprite, like I can add down sound on a Phaser.Button? I use this command:var card = gameObject.add.sprite(cardX, cardY, cardName), cardSound = gameObject.add.audio(wml.SoundAssetKeys[cardName + '_SOUND']);cardClickListener = function () { cardSound.play();};card.events.onInputDown.add(cardClickListener, card); for (i = 0; i < numOfLevelCards * 2; i += 1) { card = wml.Card.Card(cardLayout[i].x, cardLayout[i].y, (cardName), cardTimer, cardGroup, thisObject.screenObjects); cardGroup.add(card);}The problem I face is I use 'for' loop to generate all cards I have and each card has specific sound. But when I run the game only one chosen sound is played on all of the cards, placed on the stage. I also tried to use 'new' keyword for creating sound, and also Phaser.Sound() constructor, which didn't give results. Link to comment Share on other sites More sharing options...
spinnerbox Posted April 12, 2015 Author Share Posted April 12, 2015 I fixed the problem with creating constructor function that returns clickListener() custom function for each of the cards, sending all necessary external properties as arguments of the constructor. Now it works. I also think using Constructor function that returns click listener functions is best solution when it has to do some job on external objects. Note: It would be nice if there are some sound related examples http://phaser.io/examples Link to comment Share on other sites More sharing options...
Recommended Posts