SQL

Showing posts with label game. Show all posts
Showing posts with label game. Show all posts

Friday, 16 May 2014

HTML5 Audio in Games For iPad and iPhone

I have been writing an HTML5 word description game called "Word Boomer" for use on tablets and smartphones.

It was all working beautifully until I came to the seemingly minor task of adding some sound, which I left until last. "This should be easy," I thought, "thanks to the funky new <audio> tag in HTML5."

For the third time that day, I was wrong, for two reasons:

1) Many browsers for mobile devices choose not to support automatically playing a sound on page load.

2) Similarly, many mobile browsers will only allow a single audio tag per page - but my game needed two different sounds.

Problem #1 was easy enough to overcome by adding an otherwise pointless "Start Game" button for the user to click. The mobile browsers responded just fine as long as a deliberate action was taken by the user to initiate playing the sound.

Problem #2 was trickier. The best solution I found was two work with just one <audio> tag but switch its source programatically using Javascript when I needed to change from one sound to another.

Must admit there is a tiny bit of lag between the two sounds at times, but overall it works acceptably on iPhone, iPad and a variety of Android devices. Here's the code:  
var aud = document.getElementById('FuseSound1');
aud.pause();
aud.src = document.getElementById('BombSound').src;
aud.load();
aud.loop = false;
aud.play();
 Oh, oh, oh, it's magic.

Wednesday, 4 May 2011

Problems Using GIF Images In SilverLight

When first getting to grips with Silverlight, I had some problems with images.

I was creating a new Silverlight game for Play-Free-Games.com ("Panda Football" - yet another variant on the same old "Panda's playing football" theme one sees so often), and I was ready to start showing my Panda GIF images on screen.

No matter what I tried, the images were not displayed. I figured I must be specifying the path incorrectly, so I went through a long and tedious process of trying every possible relative or absolute method for defining the image path. I was on the point of tears when I tried displaying another image I happened to have to hand (a picture of a sheep - no further details required). To my intense joy, the image loaded up exactly as expected.

My initial assumption was that SilverLight does not support images of pandas, only farmyard animals. I was about to put this to the test by trying some goat, duck and chicken images when I realised that there was another key difference - my sheep pic was a jpg.

"Surely the problem isn't simply that Silverlight does not support the GIF format", I thought to myself, but not for the first time that day I was so wrong:

http://forums.silverlight.net/forums/p/39235/112333.aspx  

So, I converted my GIFs to PNGs and all was well. Cashback!