Categories
Tutorials

Looping Background Music With Intro in Godot Engine

Title is a mouthful, right? But this is something I’ve been trying and failing to find a clear answer to for months. Now that I’ve found the answer, time to take Sal‘s advice and write a blog post.

The Basic Idea

You’re making a video game. You’re using Godot because you like open source and free stuff. You’ve got some kick-awesome background music because, well, reasons. And while you can get a good loop out of the music, you’d still like to have an introduction to the music.

Background music with an intro is pretty standard in most video game music. Take a listen to “Green Hill Zone” from… well, every Sonic game ever. But particularly Sonic Mania.

Notice how when the music loops at 0:53, it doesn’t go all the way back to the beginning but instead loops from partway into the music? This helps set the stage for the level’s atmosphere and provide a more natural feel to the music.

It’s also a feature we’ve come to expect as players, so if you can do it in your game it’s a good idea. So how do we get it in Godot?

Preparing Your Music

For my game, I’m using “1977” by Adam Young as the background music. I will, of course, need to replace it with something officially licensed (or original) for the finished product. I used my copy of Ableton Live to process the audio in order to get a clean-ish loop and saved it as an Ogg Vorbis file to be imported into Godot.

Import into Godot

The key info for the loop is kept on the file itself. We want the file to loop (obviously), and we want to set the loop offset at where we want the looping portion of the file to begin. This value is in seconds!

Now for the unintuitive part: do not auto-play the music.

Selecting Autoplay here will start playback at the loop offset, which will skip the intro. That’s the exact thing we’re trying to avoid!

Instead of autoplaying, we need to add a line to the root node’s script:

What’s the difference? We’re using the play method in the AudioStreamPlayer class. This method uses an optional parameter to indicate where to start playing from. We want to start playing from the beginning, so we pass 0 to the method.

The end result should be background audio that starts playing at the beginning of the file but loops over only one specific part of it.

Hope this helps! Leave a comment if you’ve got feedback.

Categories
Uncategorized

Given the current consternation around social media, it has become more important to get the Smolblog project off the ground in a significant way. So here goes…

Follow along on GitHub

Categories
Best Of Introspection

Introducing Smolblog

Around the end of last year, I wrote an essay about what made Tumblr unique in the blogging world, followed by another essay about different technologies that can be used by a blog platform. And then I did nothing.

Well, not nothing. I went and got a new job. I also started sketching out some more concrete ideas. And while I want to be farther along in the actual development of things, I also want to start getting feedback on the ideas themselves.

Full disclosure: I’m great at talking about ideas, but I’m still learning to actually execute on them. Which is kinda disappointing, since the execution is where so many ideas go from "good" to "awesome." So, bear in mind, this is an idea. It may not get very far, it may not get very good, it may crash and burn spectacularly. But these are problems I have wanted to solve for myself, and if I can help solve them for others, then I feel that I must try. So with that, let me announce…

Categories
Analysis

Technology Cannot Make a Platform, But It Does Help

The web literally exists to share content. The first web browser was also a web editor. And ever since then, programmers have been working on ways to make publishing easier and better. As such, there’s no shortage of existing technologies that a new platform can build off of.

Categories
Analysis Best Of

What Makes A Platform, or How Do We Recreate Old Blue

It’s not enough to just make something. It’s got to be worthwhile. So if we’re going to do this, we’re going to do this right. Let’s start with the past.

Categories
Reviews

Review: Avengers: Infinity War

I appreciate the place that Avengers: Infinity War holds in the Marvel universe and in culture as a whole. I do not like it.

Spoilers below, as I would like to use this to process and discuss the movie.

Categories
Ramblings

Headcanon for Lego Batman

For the unfamiliar, a “headcanon” is a fan’s interpretation of an aspect of a work that does not necessarily align with the work as generally accepted. In a sentence: “It’s canon in my head.” What follows is my personal interpretation of The Lego Batman Movie.

Not sure if Batman spoilers but definitely Lego Movie spoilers so have a break:

Categories
Analysis Best Of

Sonic Mania and the Triumph of Fan Culture

The livestream was cutting in and out. There was a constant buzzing that replaced most of the audio. And instead of a trailer, the in-house audience saw a brief Sonic Mania logo followed by a Mac desktop. But after many fits and starts, the trailer finally played.

There’s a level of excitement around Sonic Mania that Sega hasn’t seen in roughly five years, the time since Sonic Generations was released. Fans are excited about the chance to play a new game in the vein of the classic Sega Genesis games many grew up playing. Polygon described it as “finding a long-lost Sonic title from the mid–90’s.”

But what makes Sonic Mania any different from previous Sonic games, introduced with much hype and fanfare only to be revealed as spectacularly mediocre at best? After all, this is the same company that has had many attempts to “reboot” the franchise or “return it to its roots,” often with lackluster (if not horrible) results. Is the anticipation justified this time?

The proof, as they say, is in the pudding. But this time, Sega’s investing in the right chefs. And before I try to string this metaphor out too far, let’s talk about The Avengers.

Categories
Ramblings

So I Picked a Fight With CarMax

It started with an email:

Email from CarMax saying "Evan, remember that Mini you sold us?"

Let’s see, do I remember that Mini?

Picture of sky-blue 2009 Mini Cooper hardtop with white roof, mirrors, and stripes

Yes. Yes I do. Story time: I bought that Mini February of 2009. Custom-built: no sunroof or automatic A/C, but I added in bonnet stripes, fog lamps, and sport seats. 6-speed manual transmission.

Categories
Ramblings

Satoru Iwata

My first great garage sale find was an original Nintendo Entertainment System with all the cords, 2 controllers, and 4 games including Super Mario Brothers 3 and Contra. All for seven dollars.

We sold Contra for seven dollars. I later heard about Contra and all it entails, but I don’t really regret that sale. We didn’t enjoy that game a whole lot (mostly because it was super hard), and it meant we basically got the NES for free.

Now, this was back in the days when GameStop still bought/sold classic games. We picked up original Zelda and sold it back. We found a copy of Super Mario Bros / Duck Hunt and might have sold it back; I can’t really remember.

And then we found Kirby’s Adventure.

When the Virtual Console for Wii was announced, I explained why I was looking forward to playing Kirby’s Adventure again:

First, Kirby’s Adventure is fun. Plain and simple. Not many games from this time period let you fly to get around puzzles, let alone absorb abilities from your enemies. Second, the game is expansive. There are at least six different worlds, each with several levels and minigames to boot. Third, powerups. One minute you’re throwing razor-sharp boomerangs, the next you’re a fireball, and the next you’re a floating UFO shooting laser beams. Don’t like what you’ve got? Press select and find a new one. But my personal favorite is the surprise ending, where [spoiler deleted] and you find out that [spoiler deleted].

Kirby’s Adventure is one of the best games of the 8-bit era. It has an unusual game mechanic, plenty of secret areas to discover, save files, a surprise ending, and one part even has parallax-scrolling backgrounds that most games didn’t see until the Sega Genesis / Super Nintendo era.

Satoru Iwata was a producer on that game. He’s most known for working as a programmer at HAL labs, working on games like Kirby and Earthbound (and even doubling the size of Pokemon Gold/Silver!) before moving on to become the president of Nintendo. He was there for Nintendo’s release of the Nintendo DS and Wii which were responsible for the company’s massive successes last decade, and when the 3DS and WiiU didn’t sell as planned, he himself took a pay cut. And when news of his death was released yesterday, it took so many people–myself included–by surprise.

He was an authentic president, a skilled coder, and he will be missed. Rest in peace, Iwata.