Tuesday, May 22, 2012

Early Difficulties

We've been working on this project for several months now, and made considerable progress. But it hasn't all been smooth sailing. The issues which have given us the most trouble are getting the game to work on touch screens, figuring out how to handle sound, and the particular nature of the basic structure of our code.

Touch compatibility

The touch, in particular, has been a thorn in our sides for too long. Everyone expected it to be a fairly minor addition, which would take a week or two, tops, to implement. It's been more like two months at this point, though, and while we're closer than we once were, it still hasn't clicked for some reason. The first few attempts didn't work at all, until this little section of the code in our GameObjectManager was fixed:

   // watch for keyboard/mouse/touch events   document.onkeydown = function(event){g_GameObjectManager.keyDown(event)};       document.onkeyup = function(event){g_GameObjectManager.keyUp(event)};   document.onmousedown = function(event){g_GameObjectManager.onMouseDown(event)};   document.onmouseup = function(event){g_GameObjectManager.onMouseUp(event)};   document.onmousemove = function(event){g_GameObjectManager.onMouseMove(event)};   document.ontouchstart = function(event){g_GomeObjectManager.touchStart(event)};   document.ontouchend = function(event){g_GameObjectManager.touchEnd(event)};   document.ontouchmove = function(event){g_GameObjectManager.touchMove(event)};

The last three lines used to begin with document.touchstart, document.touchend, and document.touchmove, but we eventually realized our error. (I realize that these would normally all be event listeners, but that didn't work when we tried, probably due to our code structure which I will discuss later)

With this minor fix, we got touch working a little bit. The game can recognize when the screen is touched, since the title screen, when touched, launches the game. However, the player is supposed to be able to drag their character around the game environment, and this still isn't possible. I suspect there's something wrong with the way we're getting the coordinates out of the touch event.

Sound

Next, there's the question of what we're going to do about the game's audio. This will take some consideration since we want the game to be playable on the iPhone, but Apple has restrictions for sounds in HTML5; mainly, that only one sound file can be played at a time, which makes combining sound effects and music way more difficult. But we still want to try to do so in our game, if only to prove it can be done. There's also the problem of getting the sounds loaded, since they can't be pre-loaded. When we tried, the game would say each sound was loaded, and then unload it as soon as a new sound was loaded. As such, the sounds all need to be loaded only when they're being used, which means our sound files need to be really small to load easily in a short amount of time.

Uncommon code structure

Finally, there's the way our code was set up. It uses a class-based structure, but all the classes are actually just constructors. This was based on a tutorial we found when we first started the project, but now we realize that it might have been better to use a more standard method of arranging the code. Problems are difficult to fix, since many of the potential fixes we find are incompatible with our code the way it's set up. Currently, we're working on making some changes to make the code more manageable.

At least some of these problems probably have fairly simple fixes which we only missed because of our inexperience, but at least we're learning how to handle these kinds of problems in the process. After all, this entire project is a learning experience.

No comments:

Post a Comment