3/9/2023 0 Comments Html5 audio events![]() ![]() + A tiled background "LifeBar", which is the gradient from red to green texture. + A sprite "LifeBarBorder", which is the white fixed border. The lifebar is in the layout "Game" and is composed by two objects: The lifebar is just there to visually represent this health. We've already discussed about it in the Basic Mechanics. The health itself is handled in the group "PlayerHandling" in "esGame". In this project, I chose to only represent the ship's health with a lifebar, as the "Asteroid" are a single hit and their size determines wether they split or get destroyed. It is a subject often asked, and also an interesting feedback for the player.Ī lifebar is a visual representation of the health/energy left in some object of the game. You can give the same tag to several sounds playing and apply the same volume/action to them all at once by simply naming the tag. In your own projects you can act on the volumes and playrate of your sound, in the same way you stop a sound, by naming its tag. That's it for the Audio System in this project. ![]() The same logic happens in event 7 and 8 but for the tag "Brake". The sound is stopped since the ship is thrusting no longer. You can notice the action "Audio: Stop "Thrust"". The sound is tagged "Thrust" as the "UP" key makes the ship moving forward/thrusting.Įvent 5 happens when the key "UP" is released. The sound is "JetLoop1" which is not a short sound. The same sound is played for thrust and brakes, but is tagged differently.Īs you can see event 4, the condition "System: Trigger once" is there again to only play one sound as long as the "UP" key is held down (top event 3). Nothing much to add there in regards to the previous explanations.Įvent 14 is the sound played on collision between an "Asteroid" and the player's ship.įinaly, the sounds on ship movement happens in the group "PlayerMovement". ![]() Then the "Audio: Play" action is used with the according sound name.Ĭheck in "esGame" the events 22 and 24 in the "AsteroidHandling" group which correspond to the asteroid hit and asteroid destroyed sounds. Some of these actions, we've already seen (UI1 being played in the "menus", "NewAchievement1" being played on wave's end).Īs mentioned earlier, the process is pretty much the same all the time, in a sub event that checks if the global variable "Sound" is equal to 1 (sound is turned on). ° Sounds on some actions (asteroid hit, asteroid destroyed, asteroid in collision with ship, wave end, ship movement, the player presses "return" in the "menus") This allows to play a random song each wave, in the limits of the available songs. The use of the expressions " & floor(random(0,3))" allows to concatenate (add to the string) a random number between 0 and 2 to the string "MattOglesby - " (notice the spaces). The music files in this project are named "MattOglesby - X" where X is a number from 0 to 2. The tag here is still "BackgroundMusic", so the file can be stopped at the next wave's end. The "Play (by name)" action takes several parameters: the name of the file (as a text field in which you can add variables and expressions), the folder the file is supposed to be in (either "Sounds" or "Music" here it is the "Music" folder) and a tag, as the "regular" "Play" action. Moreover, in this very example, the condition "System: Trigger once" allows to play the sound only one time, and not every tick that the key is down (which would result in multiple samples being played on top of each other and ultimately a saturating cacophony). When the player presses on the "UP" key and that the global variable "Sound" is equal to 1, a sound is played. When it is 1 it means that sound/music is on, when it is 0 music/sound is off.Īnd so, anywhere in the code that an audio action is needed, you might already have noticed a condition "System: Sound = 1" is used (often as sub event).įor example, in "esGame" event 4. ° The user can choose if he wants sounds or not (turn it on/off)Ī global variable "Sound" (in "esScore") is either of value 0 or 1. They are downloaded like sprites.īackground musics are streamed from where your project is hosted and must be imported in the music folder. Remember that sounds can be preloaded and should be small/quick files. Be sure to check " Adding sound - A beginner's guide" to learn how to add sounds and musics in C2 that can be used with the "Audio" object. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |