I did lots of bug squashing and artwork this week. The whole week was supposed to be completely focused on Stellar Combat’s art, such as (re)designing characters. I wanted a small break from programming, as I’ve been on a bit of a programming frenzy lately. It is exciting to work on Stellar Combat’s code, much more than Stellar Alien. I think the reasons for that is because the networking code is fun to work on, Stellar Combat has a better game engine that allows me to develop faster (entities have reusable logic, scene management), and overall I’m much more excited about the project than I was for Stellar Alien.
Rosso’s blowing up the galaxy with a new attack:
Above is the sprite sheet animation of Rosso’s new attack! His attack was just a tiny little red circle before but now he’s ready to own Starbli with a powerful star blast.
Rosso also is getting a makeover, just like Starbli. This more of a redesign of the whole character. He needs more touching up though, check for another post in a few days.
Added game music using howler.js:
I don’t like the HTML5 Audio tag. It is obvious that the audio tag just wasn’t meant for games. The up and coming Web Audio API is ready to deliver a more complex and powerful audio API for the web. But, the browser support for Web Audio is very poor. It has been in Chrome stable for quite a while now but only just introduced in Firefox a few versions ago.
Not bare bones though. I used an open source audio library called howler.js. Howler.js will use the Web Audio API if it’s supported in the environment, otherwise it will fall back to HTML5 Audio. That’s perfect for me, since I am considering having Stellar Combat run in the browser as well, so using Web Audio on the desktop would be great. It also has nice audio features built-in like fade in/out so I wouldn’t have to worry about implementing those things myself (I don’t find audio code interesting).
But howler.js wouldn’t work in CocoonJS out of the box. The sound didn’t seem to load and would freeze the entire game after a few seconds. The problem was really a head scratcher. I told the friendly folks over at Ludei, the company behind CocoonJS about my audio issue and they responded insanely fast (like 45 minutes…on a Sunday!!) and told me to send them a very simple example that just plays a .ogg sound and they’ll take a look at the problem.
I was going to do just that, but the example worked fine for me. The music played. So that was when I knew it was a problem specific to howler.js. After a lot of digging in the howler.js source code, I found that before they played a sound, they would check the Audio Object’s readyState property, and if the audio is not ready it would try to load it again.
The problem is that CocoonJS’s audio object doesn’t have a readyState property. So when howler.js checked if Audio.readyState === 4, the property was undefined. This made howler.js go crazy and load the audio again…and again…and again because it thought the audio never loaded.
I told a member of Ludei that their audio object is missing the readyState property and they responded telling me “Thanks!” and that it should be included in the next release. The issue was temporarily solved by manually setting an Audio instance’s readyState property to 4 in howler.js. Now the music plays!
Network Connectivity issues:
Lately there’s been a lot of inconsistent connection issues that have been having me worried about the stability of WebSockets on mobile. Luckily, the problem isn’t with anything except my networking code. It seems like my Ping/Pong timers are a little inaccurate. In Stellar Combat, the client sends a “ping” command to the server every 15 seconds.
If the client has yet to hear from the server after 15 seconds, it will assume that it has lost connection with the server and the socket hasn’t closed yet or you’re lagging way too much to be playing, in which case it will close the WebSocket connection.
This sounds pretty simple, right? Turns out I didn’t implement this correctly and it seems to be the cause of the random disconnecting. More on this issue later.
Overall, a good week of development. Leave a reply if you have a question about the game, or anything else.