Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Hi Benji, this is a fantastic tool, really having fun learning and making a game with it.

I had a question about how to implement a music file that starts 5 seconds after the startup and loops. I understand the files and folders needed, but I'm stuck as to what to put in the audio.js file to accomplish this. I'm still a beginner at Javascript, so any help you could provide would be brilliant!

(+1)

Hey, thanks! Happy to help.

If you just want a looping audio file to play five seconds after the page loads, you probably don't need to interface with text-engine at all to do that. I would just add something like this in the script tag of your HTML (or a separate script file if you have more custom code you want to add):

const audio = new Audio('audio_file.mp3');
audio.loop = true;
setTimeout(() => {
  audio.play();
}, 5000);

But if you want it to start 5 seconds after some particular event in the game, such as when the player enters a room, you could put the timeout in e.g. an `onEnter` function or etc. on your disk.

Hope this helps! If you need more help with this let me know.