Jump to content

Issue with collision and audio


Recommended Posts

Hello all, this is my first post here and I have an issue with some code.


Basically, I am working on a vertical side-scrolling game where you control a ball falling onto various platforms.  I have worked out the theme song and have no issues with that.  I also have no issues with the "game over" sound I've made.  So here is the issue I'm facing:


I have a group of sounds that correspond with the keys on a piano (i.e. I have a sound for "C", "D", etc.).  I have loaded these sounds and added them to my play state.  I want a note to play when the player (ball) lands on a platform.  Currently, I am using:


game.physics.arcade.collide(player, platforms, this.playNote, null, this);


and here is the function playNote:


playNote: function() {


in order to play the note.  As you might guess, the note plays over and over again as the player is constantly colliding with the platforms.


Does anyone have any solutions for me so that each sound can play only ONE time when the player collides with a platform?



Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...