with Imagination: by Dustin Diaz

./with Imagination

A JavaScript, CSS, XHTML web log focusing on usability and accessibility by Dustin Diaz

Yea um, so… I added sound to YUI Tetris

Thursday, May 25th, 2006

Thanks to Scott Schiller and his dandy Sound Manager (from ages ago) which allows you to embed audio into your webpage and fire them at will with JavaScript. Sounded simple enough so I dropped in the soundmanager.js file, a .swf, and then an xml file to define my sounds… then Voila! it was a piece of cake. It was as easy as dropping in the appropriate triggers in particular points of my tetris script such as moveLeft, moveRight, drop, nukeLines or rotate. I experienced first hand the benefits of writing in Object Notation when I had to go back and do some editing…

So really, you added sound!!??

Before I get hosh posh from the purist who will have liked it better without the cheesy sound effects, I just want to let everyone know… I was just having fun. And for those who barked and moaned the first time about my choice of keys to use for controlling the blocks; I had a perfectly good explanation of those, and that is that it is a mirror of the original Nintendo layout. Left hand on the directional pad (s | d | f). And your right hand on the A & B buttons (for rotating (and yes, you can rotate both directions in the original tetris!!)). In all seriousness, please don’t continue to comment on the keys. It’s literally a matter of changing like 3 lines of code.

One final sidenote

This is NOT Ajax. Sorry to disappoint. It’s a video game with animation and sounds. There is not a single instance of xmlHttpRequest in all of the code.

Now enjoy the mario bros music while playing tetris ;)

6 Responses to “Yea um, so… I added sound to YUI Tetris”

  1. Riddle

    This is NOT Ajax. Sorry to disappoint. It’s a video game with animation and sounds. There is not a single instance of xmlHttpRequest in all of the code.

    You should have written it in prev post in font-size: 10em… digg kids yelled “ajax, ajax” further than you think. :/ :(

  2. P.J. Onori

    So true. It’s funny that whenever something moves or is interactive in Javascript, people automatically assume it’s AJAX.

  3. Huseyin Tufekcilerli

    How about adding this audio stuff to new Yahoo! Mail Beta? For ex. when a new mail comes it would be good to be notified by a sound.

  4. Ali

    AJAX is communicating of a browser and a server through javascript without refreshing or changing the page. It’s clear that there is no need of AJAX here.

    I think it’s better to put the sounds in a swf, then javascript will command the flash player to play the correct sound. you might have done this way but i didn’t checked yet.

  5. Sound

    At first I thought it is Ajax too. Nevertheless, Javascript and Ajax are sometimes looking very similar :-) By the Way, I love the Mario Bros Music, it reminds me on the 90s.

  6. Freshblog

    I dont understand much about Ajax or Javascript, but the game ist really cool and the sound fits perfectly.

Leave a Reply

Phone Number:

If you're about to post code in your comment, please wrap your code with the tag-combo <pre><code>. Also please escape your html entities - otherwise they will be stripped out. I recommend using postable.

Get "JavaScript Design Patterns"

"As a web developer, you'll already know that JavaScript™ is a powerful language, allowing you to add an impressive array of dynamic functionality to otherwise static web sites. But there is more power waiting to be unlocked--JavaScript is capable of full object-oriented capabilities, and by applying OOP principles, best practices, and design patterns to your code, you can make it more powerful, more efficient, and easier to work with alone or as part of a team."

Buy JS Design Patterns from Amazon.com Buy JS Design Patterns from Apress

Flickr

Submit a Prototype

All content copyright © 2003 - 2007 under the Creative Commons License. Wanna know something? Just ask.

About | Archives | Blog Search

[x] close

Loading...

Submit a prototype

By checking this prototype I agree that I am not submitting false credentials, pornography, or a hate crime website. I also understand that by submitting my entry I may or may not be accepted, and if accepted, my entry may be taken down at any given time if I violate these terms.