Dashing through the Sound

Reddit user /u/BFKalut wants to set up a little sound effect in his game. Specifically, he wants a little sonic boom every time the player first presses dash. It shouldn’t happen continuously while the player is dashing, just the once. And, ideally, it would also play a little animation. Let’s get started!

*Incidentally, I’ve written about how you might disable/enable dash by switch, as opposed to just by map, in a separate blog post.

Sound Effect

User /u/drykul already had an excellent approach to the dash looping sound effect, and there’s no sense in reinventing the wheel. Here’s how he does it, in a single common event.

RPG Maker already has a built in way of asking if the player is dashing. The script-call

$game_player.dash?

Returns either true (player is dashing) or false (player is not). The problem for just using this for the SE is that every frame the player is dashing, the script returns true. That means we’re going to get our sound effect played 60 times every second, which is headache inducing.

So we’re going to use a switch to determine whether we’ve already played the Sound Effect once this dash. Call it something like “Mid-Dash” and note the switch ID for it.

Create your common event, make it a parallel process, and for its condition make sure that whatever you give it will be set to “on” at the time you want this SE/Animation.

Good Game Practice Note: In building larger games, these kinds of “always running common events” crop up frequently. They require a condition. Therefore, in any game you make you should have a switch called “Game Started” or “Game Initialized” or something like that which you turn on as soon as the game starts. You can use that switch here.

Parallel Process Common Events will run in the background of your *entire game,* so long as the condition switch is ON. So make them short and lag-less.

Parallel Process Common Events will run in the background of your *entire game,* so long as the condition switch is ON. So make them short and lag-less.

We want to check to see whether the player is dashing and, if they are, whether they are Mid-Dash. Make a conditional branch and use the “script” option to set your conditional branch.

You can easily blend RPG Maker's Event Editor with Script Calls. Here, if we use a Conditional Branch (instead of the Ruby if/then statement) we get to see it visually prettier.

You can easily blend RPG Maker’s Event Editor with Script Calls. Here, if we use a Conditional Branch (instead of the Ruby if/then statement) we get to see it visually prettier.

Your script should read:

$game_player.dash? && $game_switches[n] == false

Replacing “n” in the brackets with whatever the ID is for your mid-dash switch. This translate roughly to “is the player dashing and is switch N off?”

If that’s true, play the sound and set your Mid-Dash switch on. This will now work for only the first dash a player does. It will play the sound effect once and then never again. What we need to do is, once you’ve stopped dashing, turn the Mid-Dash switch off. We can do that with a loop:

Loops will continue to run until you use Break Loop.

Loops will continue to run until you use Break Loop.

Our loop checks to see if the player is dashing at all – and doesn’t consider our switch. As soon as the player stops dashing, the switch is set to OFF, the loop is broken, and we’re ready for another sound effect the next time the player dashes.

Animations

Setting up animations in RPG Maker is easy – in fact, there is an entire database tab for it. Open up the animations section and you’ll see something like this:

The default animation screen. You can build powerful animations here!

The default animation screen. You can build powerful animations here!

Here you can combine any kind of graphics, flashes, and sound effects you like to make an animation. You do this frame by frame – set a frame, then choose the next one and set a frame, and so on. Remember, this animation is going to play on the “world” map – it’s not a battle animation, it’s something that will surround your little 32×32 sprite. That means it should be small. MUCH smaller than the space you’re given to work in, and MUCH smaller than any of the default animations. We’re talking tiny here!

To resize the graphic, right click on the red box, then change the "zoom" value.

To resize the graphic, right click on the red box, then change the “zoom” value.

Up at the top is where you can time sound effects and flashes. Once your animation is set-up, choose some specific frames to time with stings. If we’re going with a dash animation, a screen flash seems unnecessary – no need to blind the player while they’re trying to run.

If you add a sound effect here, we can get rid of it in our common event and have the entire impact in one tiny little thing.

If you add a sound effect here, we can get rid of it in our common event and have the entire impact in one tiny little thing.

Once your animation is created, write down the ID next to it. You’re going to need it for this next part.

Return to your common event. If you decided to include the sound effect as part of the animation you created, you can delete the line for playing the sound effect that I described in the last section. So you’d have something like this:

The same common event, with the SE removed.

The same common event, with the SE removed.

Where that sound effect was, we’re now going to play the animation at our player’s location. Any event can have an animation play on it, it’s easy! Just use the script call:

.animation_id

With that in mind, the script call to play an animation at the player is:

$game_player.animation_id = a

Where a is equal to the animation id I told you to write down.

Add that script call where the sound effect was, and we’ll get the entire package.

Challenge

BFKalut rightfully is concerned about this effect getting annoying to a player. One possible solution is to randomize the sound effect or animation that gets played. Another is to randomize the chance it actually happens – that is, only play it 1 every 3 times the player activates dash. How might we do those things?

Check back next week for the solution!

Advertisements

One thought on “Dashing through the Sound

  1. Pingback: So Random | The Iron Shoe

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s