noodlesdefyyou Posted February 10, 2014 Share Posted February 10, 2014 Greetings and hello! After much procrastination, I have gotten myself off my rear and started actually working making games. I am starting off with extremely simple things, extremely basic, then slowly expanding upon them until I have one complete game. Anyway, I'm at a point right now where I have a canvas, the player, the player can move around and shoot. I've also got a sound effect for when the player shoots. Only problem is, I'm stumped as to how to write it up. I know I have to preload the clip. I've got game.load.audio('gunshot', 'sounds/gunshot.wav'); in my function preload(). I know I want the effect to play whenever a bullet is fired (not necessarily when fire is pressed, since i can hold down space and fire non-stop), but placing gunshot.play causes the game to crash as soon as a bullet tries to fire. I've tried various searches, but I mostly get 'phaser effects', as in the musical sense. Generic 'how to add sound effects in html' are exactly that: way too generic. I know I'm missing something somewhere, I'm just not sure where to look. The included samples don't really have the 'on event' effect I'm looking for, either. I've tried using the audio sample code to figure it out, but I am simply stumped here. I know it's something simple too. Any help would be greatly appriciated. I'm not sure if theres any other info you would require, but let me know if there is.Thanks! Link to comment Share on other sites More sharing options...
jpdev Posted February 10, 2014 Share Posted February 10, 2014 "but placing gunshot.play causes the game to crash as soon as a bullet tries to fire." When ever your game crashes, it is really important to check why.The simple way to do this is to open the Console of the browser and check for the error message that accompanies such a crash. (F12 on Chrome and Firefox) Post that information here, and we'll figure out what goes wrong. You could also check out this example:http://gametest.mobi/phaser/examples/_site/view_full.html?d=audio&f=play+music.js&t=play%20music preload the sound in the preload methodcreate the sound in the create method play it, where every ou have access to the variable you created it in. Link to comment Share on other sites More sharing options...
noodlesdefyyou Posted February 11, 2014 Author Share Posted February 11, 2014 I actually fixed this right after I submitted the post. I had the shot.play() under the wrong bracket. Link to comment Share on other sites More sharing options...
Recommended Posts