Jump to content

  • Log In with Google      Sign In   
  • Create Account






Starting a game in HTML5

Posted by shadowisadog, 08 June 2011 · 539 views

So recently I have become interested in HTML5 and the new Canvas tag from a development perspective. Browser adoption is starting to catch up to the standard (although Firefox's Canvas element is still slow compares to IE9 and Chrome which is a bit lame) and HTML5 is starting to look like an attractive game/simulation development option.

My plan is to build a top down, tile based game with A* pathfinding and smooth tile scrolling. I want it to have all mouse driven interactions (following the golden rule of casual development), simple vector based graphics (created in Inkscape), and simple and laid back game play.

Starting development in such an early technology can be a bit of a dark alley. Sure there are some enterprising developers creating some game libraries for HTML5 development (such as MelonJS) and some examples/tutorials on the subject, but over all the whole thing feels a bit mysterious.

My intention is to create my own simple game framework built directly on HTML5 without using an existing game library for HTML5 and without resorting to any conversion technologies. The idea behind this is that I am not making a game for the sake of creating a game, but for the sake of learning the technology of HTML5 for multiple potential applications.

My current progress has looked at how to structure the game and what sort of IDE to use to comfortably write HTML5 content. I have settled upon Netbeans 7 as my IDE of choice. It supports HTML5 editing and has all of the tools that I need. I simply created a php project and removed any files it generated/configured my ftp settings to automatically upload the files to my webserver. It allows me to remain organized in my coding!

The only external library I am using as of late is jQuery. This is simply too helpful to pass up as it really simplifies a great number of javascript tasks such as trying to include external js files in js files (I was looking for a way to do include style statements to make the code more manageable, but some structural changes needed to be made because the call is asynchronous).

Here is a wip shot from the current title screen that I am using for testing. The game centers around a smiley face (simple art assets) on a quest to gain happiness after losing the love of its life in an IM conversation.

Posted Image

Here is some of the very basic and potentially horrible html5 im using:

<!DOCTYPE html>
<html>
	<head>
    	<title>Journey of a Grin</title>
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    	<link href="style.css" rel="stylesheet" type="text/css"> 
    	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
    	<script src="scripts/main.js"></script>
    	
	</head>
	<body onLoad="initGame('game')">
    	<h2>Journey of a Grin</h2>
    	<canvas id="game" width="800" height="600">
        	Unfortunately your browser does not support the HTML5 canvas element!
    	</canvas>
	</body>
</html>





I was thinking of doing this, but thinking of using JavaScript makes me feel disgusting.

It looks like a language that makes large projects a hard to manage mess.

I was thinking of doing this, but thinking of using JavaScript makes me feel disgusting.

It looks like a language that makes large projects a hard to manage mess.



I am not so sure about all of that. If Javascript is not your style though there are conversion tools such as Wallaby for Flash to HTML5 conversion.In my experience so far Javascript is "different" then some other languages but different does not necessarily mean that the code will be a "hard to manage mess". I think the main thing is that you have to work with the language rather than trying to force the language to do things that it does not handle... For instance for inheritance there is prototypes however there exist a number of other schemes for inheritance as well. The more of these other schemes you use, the more hackish your code may start to appear... but it really depends on what you absolutely need!

For my game I plan to try to implement a component based architecture (having made enough games with deep inheritance hierarchies and suffered the consequences)... and yes I HAVE looked at functional reactive programming, but I am not sure if that is anything more than a vague arcane black magic that is outside the scope of mere mortals...
You do make a good point, however the way that classes \ objects, script 'includes' and whatnot are handled it just seems really really hard to manage. I mean will you be having separate script files for each 'object constructor function' because that's all a class really is in JavaScript, right?

Yeah I agree on the functional reactive programming, such high level explanations with no real examples. At my current understanding of it, it just seems like don't code functionality or generic code for the hell of it, code what you want done when you want it, which is what I do with my code...

Anywho, I will be watching your journal!

September 2014 »

S M T W T F S
 123456
78910111213
14 15 1617181920
21222324252627
282930    
PARTNERS