Tuesday, February 19, 2013

Your Daily digest for Tech Geek`s Tools, Tips, Tricks and Tutorials

Tech Geek`s Tools, Tips, Tricks and Tutorials
Pipes Output
Large Corporations Displacing Aging IT Workers With H1-B Visa Workers
Feb 19th 2013, 23:17

New submitter genericmk writes "NPR is running an interesting story about the unfortunate status of the aging programmers in the IT industry. Older IT workers are opposing the H1-B visa overhaul. Large corporations want more visa, they claim, because of a shortage of IT talent. However, these companies are actively avoiding older, more experienced workers, and are bringing in large volumes of foreign staff. The younger, foreign workers are often easier to control, and they demand lower wages; indentured servitude is replacing higher cost labor."

Share on Google+

Read more of this story at Slashdot.



Monsanto's 'Terminator' Seeds Set To Make a Comeback
Feb 19th 2013, 22:34

ananyo writes "Monsanto and other biotechnology firms could be looking to bring back 'terminator' seed technology. The seeds are genetically engineered so that crops grown from them produce sterile seed. They prompted such an outcry that, as Slashdot noted, Monsanto's chief executive pledged not to commercialize them. But a case in the U.S. Supreme Court could allow farmers to plant the progeny of GM seeds rather than buying new seeds from Monsanto, making the technology attractive to biotech companies again. Some environmentalists also see 'terminator' seeds as a way of avoiding GM crops contaminating organic/non-GM crops." Reader 9gezegen adds that Monsanto is getting support, oddly, from parts of the software industry. From the NY Times: "BSA/The Software Alliance, which represents companies like Apple and Microsoft, said in a brief that a decision against Monsanto might 'facilitate software piracy on a broad scale' because software can be easily replicated. But it also said that a decision that goes too far the other way could make nuisance software patent infringement lawsuits too easy to file." The case was heard today; here is a transcript (PDF), and a clear explanation of what the case is about.

Share on Google+

Read more of this story at Slashdot.



Does the Higgs Boson Reveal Our Universe's Doomsday?
Feb 19th 2013, 21:53

astroengine writes "If calculations of the newly discovered Higgs boson particle are correct, one day, tens of billions of years from now, the universe will disappear at the speed of light, replaced by a strange, alternative dimension, one theoretical physicist calls boring. 'It may be that the universe we live in is inherently unstable and at some point billions of years from now it's all going to get wiped out. This has to do with the Higgs energy field itself,' Joseph Lykken, with the Fermi National Accelerator Laboratory in Batavia, Ill., said. 'This calculation tells you that many tens of billions of years from now there'll be a catastrophe.'"

Share on Google+

Read more of this story at Slashdot.



Firefox 19 Launches With Built-In PDF Viewer
Feb 19th 2013, 21:10

An anonymous reader writes "Mozilla on Tuesday officially launched Firefox 19 for Windows, Mac, Linux, and Android. The improvements include a built-in PDF viewer on the desktop and theme support as well as lower CPU requirements on Google's mobile platform. You can see the official changelogs here: desktop and Android."

Share on Google+

Read more of this story at Slashdot.



Apple Hit By Hackers Who Targeted Facebook
Feb 19th 2013, 20:26

snydeq writes "Apple was recently attacked by hackers who infected the Macintosh computers of some employees, the company said on Tuesday in an unprecedented disclosure that described the widest known cyber attacks against Apple-made computers to date, Reuters reports. 'The same software, which infected Macs by exploiting a flaw in a version of Oracle Corp's Java software used as a plug-in on Web browsers, was used to launch attacks against Facebook, which the social network disclosed on Friday. ... A person briefed on the investigation into the attacks said that hundreds of companies, including defense contractors, had been infected with the same malicious software, or malware. The attacks mark the highest-profile cyber attacks to date on businesses running Mac computers.'"

Share on Google+

Read more of this story at Slashdot.



NASA Loses Contact With Space Station Over Software Update
Feb 19th 2013, 20:08

kodiaktau writes "Reports early Tuesday morning say that a software update to the International Space Station caused a communications blackout with Houston control. Remediation of the update has allowed the astronauts limited communication every 90 minutes or so. It is expected that the issue will be resolved today."

Share on Google+

Read more of this story at Slashdot.



Update — Sensors Do Not Pick Up North Korean Radioactivity
Feb 19th 2013, 19:45

Update: 02/19 20:49 GMT by S : The story below has been retracted upon further examination of the research. There has been no detection of radioactivity. gbrumfiel writes "A global network of sensors has picked up faint traces of radioactive gas that probably seeped from last week's underground nuclear test by North Korea. The detection of xenon-133 in Japan and Russia provides further evidence of the nuclear nature of the test, but offers no hint as to the type of weapon used. Atmospheric modelling by the Central Institute for Meteorology and Geodynamics in Vienna shows that the gas likely seeped from North Korea's test site on 15 February, three days after the original test. That indicates that the test was well sealed deep underground."

Share on Google+

Read more of this story at Slashdot.

Sensors Pick Up North Korean Radioactivity
Feb 19th 2013, 19:45

gbrumfiel writes "A global network of sensors has picked up faint traces of radioactive gas that probably seeped from last week's underground nuclear test by North Korea. The detection of xenon-133 in Japan and Russia provides further evidence of the nuclear nature of the test, but offers no hint as to the type of weapon used. Atmospheric modelling by the Central Institute for Meteorology and Geodynamics in Vienna shows that the gas likely seeped from North Korea's test site on 15 February, three days after the original test. That indicates that the test was well sealed deep underground."

Share on Google+

Read more of this story at Slashdot.



HTC Unveils Revamped HTC One
Feb 19th 2013, 19:03

adeelarshad82 writes "Earlier today, HTC unveiled a revamped version of its One smartphone. The new HTC One has a 4.7-inch full HD 1080p display which is powered by a 1.7-GHz, quad-core Qualcomm Snapdragon 600 processor and a customized version of Android. The new phone includes support for NFC, Bluetooth 4.0, and DLNA for wireless streaming to a TV or computer. Measuring 5.4 by 2.7 by 0.36 inches, the phone weighs around 5 ounces. According to the specs, the phone will come with either 32 or 64GB of storage and 2GB of RAM, and it's backed by a non-removable 2300mAh battery. Unfortunately the phone doesn't include a memory card slot and has just two ports: a headphone jack and a MicroUSB that doubles as an MHL output for HDMI TVs. HTC One's 'UltraPixel' camera is nothing to sniff at either. HTC is trying to replace megapixels with 'ultrapixels,' cutting down the size of photos but using much larger individual pixels to sharply reduce noise and improve low-light performance. In a quick comparison with iPhone 5 and Galaxy S3, One's images were far clearer and brighter. The HTC One runs Android 4.1.2 with HTC's new Sense 5."

Share on Google+

Read more of this story at Slashdot.



Oxford Temporarily Blocks Google Docs To Fight Phishing
Feb 19th 2013, 18:21

netbuzz writes "Fed up with phishers using Google Forms to commandeer campus email accounts as spam engines, Oxford University recently blocked access to Google Docs for two-and-a-half hours in what it called an 'extreme action' designed to get the attention of both its users and Google. 'Seeing multiple such incidents the other afternoon tipped things over the edge,' Oxford explains in a blog post. 'We considered these to be exceptional circumstances and felt that the impact on legitimate University business by temporarily suspending access to Google Docs was outweighed by the risks to University business by not taking such action.' The move generated widespread complaints from those affected, as well as criticism from outside network professionals."

Share on Google+

Read more of this story at Slashdot.



Senior Game Designer Talks About Game Violence, Real Violence, and Lead (Video)
Feb 19th 2013, 17:45

William Volk may not be the world's oldest game designer, but he's up there. He started out as a play tester for Avalon Hill in 1979, and since then has worked for Activision and other major players in the game space. His current job is with PlayScreen, where he's working on their Word Carnivale iOS game, which is not violent at all. But over the years Volk has worked on slightly violent video games and has watched public outcries over video game violence since 1976. He's also tracked how much less violence we've seen since lead was removed from gasoline. (Editorial interjection: Aren't most remaining pockets of massive gun violence in cities where many poor kids grow up in apartments that have lead paint?) Due to technical problems during the interview, some of the conversation is missing, primarily about the recent spate of multiple murders. It seems, for instance, that Newtown shooter Adam Lanza was heavily into violent video games, which is sure to spark plenty of new discussion about how they affect players. But then again, as Volk reminded me in an email, "If people were influenced by video games, a majority of Facebook users would be farmers by now," a meme that has been floating around Facebook since last year, if not earlier.

Share on Google+

Read more of this story at Slashdot.



Ubuntu For Tablets Announced
Feb 19th 2013, 17:04

hypnosec writes "Keeping its promise from yesterday Ubuntu has announced an operating system for tablets dubbed 'Ubuntu for Tablets' that it says will work on tablets of any size. Advertised to work on both entry level tablets as well as high-end tablets with enterprise specifications, the operating system offers multitasking, safer sharing, instant launch of applications through the menu bar on the left, effortless switching between applications among other features." The tablet version of the OS will also be presented at Mobile World Congress later this month. Also featured at SlashCloud.

Share on Google+

Read more of this story at Slashdot.



Duke Nukem 3D Code Review
Feb 19th 2013, 16:25

alancronin writes "Similar to Fabien Sanglard's previous code reviews of other games such as the Quake and Doom line of games comes a review of the code base of Duke Nukem 3D (split out over 4 pages). This will be a very good read for anyone interested in understanding the mechanics of a highly addictive game or anyone that wants to learn more about game design."

Share on Google+

Read more of this story at Slashdot.



Duke Nuken 3D Code Review
Feb 19th 2013, 16:25

alancronin writes "Similar to Fabien Sanglard's previous code reviews of other games such as the Quake and Doom line of games comes a review of the code base of Duke Nukem 3D (split out over 4 pages). This will be a very good read for anyone interested in understanding the mechanics of a highly addictive game or anyone that wants to learn more about game design."

Share on Google+

Read more of this story at Slashdot.



NVIDIA GeForce GTX TITAN Uses 7.1 Billion Transistor GK110 GPU
Feb 19th 2013, 15:46

Vigile writes "NVIDIA's new GeForce GTX TITAN graphics card is being announced today and is utilizing the GK110 GPU first announced in May of 2012 for HPC and supercomputing markets. The GPU touts computing horsepower at 4.5 TFLOPS provided by the 2,688 single precision cores, 896 double precision cores, a 384-bit memory bus and 6GB of on-board memory doubling the included frame buffer that AMD's Radeon HD 7970 uses. With a make up of 7.1 billion transistors and a 551 mm^2 die size, GK110 is very close to the reticle limit for current lithography technology! The GTX TITAN introduces a new GPU Boost revision based on real-time temperature monitoring and support for monitor refresh rate overclocking that will entice gamers and with a $999 price tag, the card could be one of the best GPGPU options on the market." HotHardware says the card "will easily be the most powerful single-GPU powered graphics card available when it ships, with relatively quiet operation and lower power consumption than the previous generation GeForce GTX 690 dual-GPU card."

Share on Google+

Read more of this story at Slashdot.



Maintainable Code: Using White Space For Readability In HTML And CSS
Feb 19th 2013, 13:51


  

Right up front, I'll offer some simple advice: In production, your code should be as performance-friendly as possible. This means, Gzip'ing, concatenating and minifying as many assets as possible, thus serving the smallest possible files and the least number of files. I don't think anyone would argue that these suggestions aren't best practices (even if we don't implement them in every project).

labyrinth-comic
Well-written, readable code doesn’t create mind games and labyrinths when other developers read it. (Image: Toca Boca)

Now that we've got that out of the way, how can we use white space in development code to ensure that our files are as readable and maintainable as possible? Well, we could consider a number of options, starting with some basics.

Basic HTML Indentation

I think most if not all of us add basic indentation in our HTML:

<header>      <hgroup>      <h1>Section title</h1>      <h2>Tagline</h2>    </hgroup>      <nav>      <ul>        <li><a href="/">Home</a></li>        <li><a href="/about/">About</a></li>        <li><a href="/services/">Services</a></li>        <li><a href="/contact/">Contact</a></li>      </ul>    </nav>    </header>    <div class="main">    <p>Content goes here.</p>  </div>

The principle here is that whenever something is nested, you indent, so that it's clear where everything is in the markup's hierarchy. With simple HTML nesting, the content in the <head> section is often neglected, but keeping the nesting consistent here, too, is good practice.

For example, the following sample code is fairly readable, even with no nesting:

<!DOCTYPE html>  <html>  <head>  <title>Foo</title>  </head>  <body>  <!-- content… -->  </body>  </html>

However, with much more content in the <head> section, nesting could make it easier to scan the contents:

<!doctype html>  <html class="no-js" lang="en">    <head>      <meta charset="utf-8">      <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">      <title>HTML5 Please - Use the new and shiny responsibly</title>      <meta name="description" content="Look up HTML5, CSS3, etc features, know if they are ready for use, and if so find out how you should use them - with polyfills, fallbacks or as they are.">      <meta content="width=device-width, initial-scale=1.0" name="viewport">        <link rel="shortcut icon" href="favicon.ico" />      <link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-114x114-precomposed.png">      <link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon-72x72-precomposed.png">      <link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png">        <link href="http://fonts.googleapis.com/css?family=Francois+One|Open+Sans:400italic,400,800" rel="stylesheet">      <link href="css/style.css" rel="stylesheet">      <script src="js/libs/modernizr-2.0.min.js"></script>      <script>if (location.host == 'h5bp.github.com') location.href = '//html5please.us/'</script>      </head>    <body id="gfs">      <!-- content… -->    </body>  </html>

This last chunk of code is taken from the HTML5 Please website. As you can see, when the content in the <head> section starts to get larger, indenting makes things a bit easier to digest at a glance. Notice that the <head> and <body> elements are indented, because they are both immediate children of the <html> element.

Of course, some developers might have a slightly different method of indenting in certain areas, but the idea is basically the same; the intention is to make the code easier to read in a development environment.

Basic CSS Indentation

In addition to indenting HTML, many developers (me included) will do matching indentation in any corresponding CSS. The following code would match the HTML shown in the first example above:

header {      color: blue;  }        hgroup {          color: green;      }            hgroup h1 {              line-height: 1.5;          }            hgroup h2 {              font-size: 15px;          }        nav {          background: purple;      }            nav ul {              float: left;          }                nav ul li {                  font-size: 20px;              }                    nav ul li a, nav ul li a:visited {                      text-decoration: none;                  }    .main {      border: solid 1px #ccc;  }

To some, this seems a bit obsessive. But I prefer it because it helps me to scan the CSS and find matching hierarchies without having to read each selector. Of course, this type of hierarchy in your CSS should be used sparingly if you're implementing modular CSS principles that encourage class-based modules and limited use of the descendant selector (for example, ul li).

Certainly, some of the code above is kind of awful; I wouldn't recommend tying your heading and list styles to a specific context like that. But for the purpose of understanding this concept of indenting CSS, look at it as a theoretical example.

The point is that you have the option to indent CSS to match the HTML's structure, thus making it easier to scan and easier to make sense of relative to the markup.

Of course, as is the case with a few things mentioned in this post, some of this doesn't apply when you're using a CSS preprocessor. For example, the nested selectors option for Sass would make this last tip quite different in such an environment.

Readable CSS3

Let's take our abuse of white space even further. Many new CSS3 features allow for either comma-separated or space-separated value sets. Two simple examples are multiple backgrounds and transforms. Let's see how we can make these easier to read:

.example {      background: url(images/example.png) center center no-repeat,                  url(images/example-2.png) top left repeat,                  url(images/example-3.png) top right no-repeat;  }    .example-2 {      transform: scale(.8)                 skew(20deg, 30deg)                 translateZ(0);  }

Notice what we've done here? Instead of keeping the entire value on a single line (which can get lengthy in some cases — especially when gradients and vendor prefixes are involved), we've put each value set on a new line, aligned with the one above it.

Thus, each of the three backgrounds is on its own line, and each transform function is on its own line, left-aligned with the first of each example.

Generally, this might go against the idea of having a single property per line (assuming, of course, that you're not doing single-line rule sets). But when compared to the alternative of potentially really long lines, this is a good option, and it makes these rule sets very easy to read.

Dealing With Vendor Prefixes

As mentioned, if you're preprocessing your CSS or using -prefix-free, then this advice doesn't apply. But you could manipulate white space to make your vendor prefixes easier to read at a glance:

.example {      -webkit-transform: scale(.8);         -moz-transform: scale(.8);           -o-transform: scale(.8);              transform: scale(.8);  }

Here we've lined up the colons so that the values align, making it easy to scan all values to ensure they're the same. I can't tell you how many times I've adjusted only the WebKit value in a rule set like this and forgotten to do the rest. Of course, this illustrates the importance of preprocessing, but if you're not doing that yet, then this use of white space is a good option to consider.

Additionally, many text editors offer a feature called "block edit" or multiline editing. This is available in Sublime Text, Vim, Coda and probably most others. Using this feature is that much easier when the values you're changing are aligned vertically.

Readable File References

The gist of this next suggestion comes from a tweet by Twitter Bootstrap cofounder Jacob Thornton. The idea here is that if a list of file references is contained in your document, you can make them easier to read by doing something like the following:

<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">  <link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">                  <link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">                                 <link rel="shortcut icon" href="assets/ico/favicon.png">

The example above is taken directly from Bootstrap. Here, all href attributes of the <link> elements are aligned. This makes it easier to refer to or adjust a <link> tag because the update will usually be to the value of the href attribute.

Of course, this somewhat violates the rules of indenting HTML. So, alternatively, you could opt for this:

<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">  <link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">  <link rel="apple-touch-icon-precomposed" sizes="72x72"   href="assets/ico/apple-touch-icon-72-precomposed.png">  <link rel="apple-touch-icon-precomposed"                 href="assets/ico/apple-touch-icon-57-precomposed.png">  <link rel="shortcut icon"                                href="assets/ico/favicon.png">

This latter example seems cleaner and has the bonus of aligning the other attributes, although that's not as necessary in my opinion.

But wait. What if you don't care that the href attribute is listed last (which seems to be the custom and is unnecessary for validation)? Then you could do this instead:

<link href="assets/ico/apple-touch-icon-144-precomposed.png" rel="apple-touch-icon-precomposed" sizes="144x144">  <link href="assets/ico/apple-touch-icon-114-precomposed.png" rel="apple-touch-icon-precomposed" sizes="114x114">  <link href="assets/ico/apple-touch-icon-72-precomposed.png" rel="apple-touch-icon-precomposed" sizes="72x72">  <link href="assets/ico/apple-touch-icon-57-precomposed.png" rel="apple-touch-icon-precomposed">  <link href="assets/ico/favicon.png" rel="shortcut icon">

No white space tricks needed here, because the href attributes align just fine. But if you're bothered by the lack of alignment of the other attributes, or if you just can't stand the thought of the href attribute being listed first, then you'll have to opt for one of the preceding solutions.

Readable Conditional Classes

The concept behind the alignment of attributes is nothing new. HTML5 Boilerplate has been doing this sort of thing for some time now with its IE conditional classes. Here's what that chunk of code looks like in the latest version:

<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->  <!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->  <!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->  <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->

In this case, the class attribute on the opening <html> tag in each conditional (and, incidentally, the tag itself) is being aligned, because this is the part of the code that's most relevant to readability and maintenance, and the part of the code that would suffer most in readability if this alignment were not present.

Readable Comma-Separated Selectors

Sticking with Boilerplate, let's go back to CSS. Here's something used in that project's main style sheet:

html,  button,  input,  select,  textarea {      color: #222;  }

Here, instead of keeping all of the comma-separated selectors on a single line — which would be more difficult to scan — each selector is put on a new line. This can be helpful when the selectors are somewhat lengthy, as in this next example, also taken from Boilerplate:

.visuallyhidden.focusable:active,  .visuallyhidden.focusable:focus {      clip: auto;      height: auto;      margin: 0;      overflow: visible;      position: static;      width: auto;  }

Similar to the idea behind aligning HTML attributes discussed above, this vertical alignment makes the code a breeze to scan through when compared to scanning a single seemingly never-ending line of comma-separated selectors.

Can Your Text Editor Help With Any Of This?

As a long-time developer who has grown accustomed to coding by hand, my knowledge of the features of different text editors is fairly limited.

Some text editors or IDEs might do some of this automatically. Also, plugin developers can use some of these patterns to create plugins or extensions that do this sort of thing automatically or at the click of a button.

If you have any suggestions of built-in tools or extensions to text editors that can assist with this, I'm sure Smashing Magazine's readers would be glad to hear about them.

Conclusion

We're all encouraged to do whatever we can to make code in a development environment as easy to read and maintain as possible. I hope these suggestions will improve your code in this way.

And knowing that this use of white space won't bloat our files is comforting — after all, this is not for production code. So, do whatever you feel is necessary to make your HTML and CSS easier to deal with, and be sure to minify those assets when deploying to production.

Finally, if you have any suggestions on using white space in HTML or CSS, we'd be glad to hear them.

(al)


© Louis Lazaris for Smashing Magazine, 2013.

A Fully Responsive HTML5, CSS & JavaScript Toolkit
Feb 19th 2013, 07:10

Advertise here via BSA

Groundwork is a fully responsive HTML5, CSS and Javascript toolkit. Using Groundwork, you can quickly build web apps that work on virtually any device. Groundwork has been built from the ground up with the incredibly powerful CSS preprocessor, Sass.

Featuring an incredibly flexible, nestable, fluid grid system: the Groundwork grid system supports any columns in any fractional amount from halves to twelths. Groundwork is open-source, hosted on Github and 100% free.

groundwork

Requirements: Sass & Compass
Demo: http://groundwork.sidereel.com/
License: MIT License

Sponsors

Professional Web Icons for Your Websites and Applications

A Complete Guide for Building HTML5 Games
Feb 19th 2013, 07:01

Advertise here via BSA

I'm currently spending most of my time explaining to students, hobbyists, professional developers and teachers how to build games using HTML5. I then recently thought: rather than keeping all these details for small audiences, wouldn't it be smarter to share it with you?

This article is then based on my own experience. I will probably omit some crucial things some of you may know. But it will try to update this blog post along with my own new discovers and of course based on the feedbacks you will kindly provide in the comments or via Twitter.

But why are so many people currently interested in HTML5 Gaming?

Well, simply because today, we can really use HTML5 to target multi-platforms using the same code: for desktop machines of course (with IE9/IE10, Firefox, Chrome, Opera & Safari), for iOS & Android tablets & phones and Windows 8, and its future associated millions of tablets & PC, is also warmly welcoming HTML5 Games! I then frequently see some HTML5 gaming projects ported to each of these platforms with almost no effort.

What's more, the modern JavaScript engines performance coupled with the GPU hardware-accelerated graphics layers enable us to build great games in HTML5 with confidence.

Note: we will only talk about the <canvas> tag of HTML5 and about SVG in this article.

Canvas & SVG: 2 ways to draw on the screen

The first thing you need to understand before building your first HTML5 game is how to draw nice objects on the screen. There are 2 ways to do that and to better understand their differences, you should start by reading this article from Patrick Dengler (member of the SVG W3C Working Group): Thoughts on when to use Canvas and SVG

On my side, I've re-used parts of Patrick's materials to build a 45min internal session for my Microsoft's colleagues last year. You can watch it via this video I've made (using HTML5 <video> of course!):

And here are the slides:

At last, you can download the source code I'm demonstrating in this video here: Mix11SVGCanvas.zip

You may have a look also to these 2 great sessions from MIX11:

Once you will have reviewed all this content, you will probably better understand why almost all HTML5 games are using Canvas rather than SVG. Canvas offers a well-known development model for games developers (low level drawing APIs) and is now very well hardware-accelerated by most of the recent browsers. Still SVG, and its vectors-based technology, is naturally better armed to scale across devices without loosing quality. You just need to use the magic ViewBox property of SVG which will handle that for you. Your games assets will then scale from 3 to 80'' screens in a very easy way!

Sometimes, it is even possible to achieve the exact same game using both technologies. For instance, here is the same simple game first using SVG then Canvas: SVG Racketball & Canvas Racquetball They are both issued from this MSDN documentation: Programming Simple Games Using Canvas or SVG

In this case, analyzing the performance of each technology could help you to decide which one to use for your game. For instance, here is an 2 interesting experiments that will display 1000 small balls on your screen using SVG: 1000 balls in SVG and using Canvas: 1000 balls in Canvas. Test both experiments in your favorite browser. In general, the Canvas performance is better for drawing a lot of objects on the screen in this special case. But this is generally also what we'd like to achieve in our video games. To have a better overview of the performance comparison, here is an interesting diagram to look at:

But nothing prevents you from mixing both technologies. Indeed, we could perfectly imagine using a first layer based on SVG to display the game menus with a second layer in background using a canvas for the game itself. You will then use what we call the browser compositing engine. However, you must pay some real attentions to final performance results because the browsers & devices are far from being equals in this domain. Don't forget that the main interest of HTML5 is to target all platforms.

My colleague David Catuhe has realized a couple of months ago a little brick breaker game using this composition principle: How to write a small game using HTML5 and JavaScript–BrikBrok . The first layer is using SVG for the bricks to break and the background can display a tunnel effect using the canvas tag. You can perfectly mimic this concept to display the main game in background (hosting a plateformer or shoot'em up game, etc.) instead of the tunnel and your first layer will simply display the menus & configuration options in SVG.

Useful libraries & tools

Graphics

Writing the XML nodes of SVG manually or even playing with the low level APIs of Canvas could be fun for a moment but not very productive. Here is then a useful set of tools & libraries I like that could help you building parts of your HTML5 game.

To generate some SVG, here are some cool tools:

  • InkScape: a free & open source desktop software
  • SVG Editor: an online software running directly inside your browser

Adobe Illustrator also supports SVG as an export target but it's a bit more expensive.

If you're looking for your game assets (for menus or controls), you should have a look to this free icons library: The Noun Project. So if you're not lucky enough to work with a designer, it could save you. There is another library with some free SVG content also here: Open Clip Art Library

To conclude on SVG, THE ultimate library you have to know is named RaphaelJS. It's a JavaScript library that will help you generating dynamic SVG with few lines of code. You'll find a lot of cool demos on the website using for instance nonlinear animation functions on SVG elements, animated charts, etc. But if you're looking specifically for charting (let's say to display some players' stats), THE ultimate charting library is named HighCharts. Those 2 libraries are so awesome that they even implement VML fallbacks for IE8 or older versions. But this shouldn't be something to worry about if you're building HTML5 games. You'll probably target at least IE9 and above.

If you'd like to display charts using Canvas, I'm a huge fan of the JavaScript InfoVis Toolkit library. Just have a look to their demos on their website, it's just awesome and simple to use.

Let's continue on the graphics side. There is a very well-known library built to simplify the usage of 3D in JavaScript named ThreeJS. Most of the time, it is used to render some hardware-accelerated 3D via WebGL. But you can ask for a rendering inside the 2D canvas element of HTML5. For that, simply check the "CanvasRenderer examples" section of the site. This is the library we've used for instance to build our Galactic demo on the IE Test Drive. Using the "CanvasRenderer", you can then build 3D scenes working in all HTML5 browsers. Something that could be good to know.

Note: we can also combine all of these graphics effects with the usage of CSS3 2D & 3D Transforms coupled with transitions or animations in your game. But I've decided to stay focused on Canvas & SVG in this article.

Physics Engine

Of course, displaying graphics is far from being the only task you need to do in a game. There is also the AI (Artificial Intelligence) you need to code to bring life to your characters. Unfortunately, you will need to code that alone and be creative. But you will be glad to know you don't need to worry about the physics & collisions part of your game. Simply learn to how to use Box2D JS. Go play with the various samples and you'll be amazed:

If you're interested in this topic, you should then read the excellent tutorials series of Seth Ladd here: Box2D orientation for the JavaScript developer . Seth even used the Web Workers to compute the physics on the several available cores of your CPU. If you don't know what the Web Workers are, I've written an introduction on these new APIs here: Introduction to the HTML5 Web Workers: the JavaScript multithreading approach . It could be useful in certain scenarios for your games.

Handling the multi touch events

If you'd like to build a cross-devices game, you will have to support touch. Currently, there are 2 existing specifications around Touch Events. So there is no official standard one yet. If you'd like to know a bit more why, here is an interesting article: Getting Touchy About Patents

You will need to write code working fine inside IE10 & Windows 8 as well as with the implementation coming from the Apple devices. For that, you should definitely have a look to this sample demonstrating a possible pattern to support both kind of touch events: Finger Painting and its associated article: Handling Multi-touch and Mouse Input in All Browsers. But if you're interesting in checking how far you can now go by handling multi-touch inside IE10, test this cool demo: Browser Surface . You'll need a recent IE10 version and a multitouch hardware running it.

Boris Smus has started working on his side on a library named Pointer.js. The idea is to consolidate all types of touch (IE10, iOS like, mouse and pen) to simplify your developer life. You can read his article about that here: Generalized input on the cross-device web . Currently, the library is just a draft and doesn't support yet the MSPointer* of IE10. So feel free to contribute to the project to help him! (I've planned to try to help him when I will have some spare time).

Building connected games

If you'd like to build multiplayers games or simply a connected game to a server for any reason, you'll be naturally interested by using WebSockets. This W3C specification (and the underlying protocol handled by the IETF) is indeed stable enough to start to be used in production.

But if you'd like to support the widest possible number of users, you need to consider a fallback for browsers or devices which weren't supporting WebSockets yet or were supporting an older deprecated version. Well, we could even dream of solutions automatically falling back to older method of pooling or long pooling for browsers like IE9 and offering Web Sockets to more recent browsers like IE10. And yes, could it be possible also to have a unique code handling that?

Well, stop dreaming, the community made it. There are 2 solutions I know doing that on my side:

Both libraries will help you to handle all the browsers & devices with their variety of support levels.

Some gaming frameworks

To build a 2D HTML5 game, there are several things you need to carry about:

1 – Handling your sprites: splitting them into a sequence, animating them, effects, etc. 2 – Handling your sounds & music (and this is not something easy in HTML5!) 3 – Loading asynchronously your assets from the web server via a dedicated loader/assets manager 4 – Building a collision engine, a high level logic for your game objects, etc.

Well, you can either do that starting from scratch or you can test & review what other brilliant developers have already done on the web. I'll definitely advice you the second option as the JS gaming frameworks start to be really mature and tested inside games in production.

As there is a ton of JS gaming frameworks on the web (well, there is a ton of anything.JS actually), here are the most well-known frameworks I know to build HTML5 2D games working inside all browsers:

  • MelonJS : a free framework that exposes a lot of useful services. His big advantage is that it works fine with the Tiled Map Editor tool.
  • CraftyJS that I unfortunately don't know very well
  • ImpactJS : a high quality well-known framework. It's not free but not too much expensive.
  • EaselJS : my favorite one ! Written by an old flash developer. So if you have written some games in Flash, you should feel at home with this framework. It's part of the CreateJS suite. It's very complete, well documented and… free.

So, you should now be warn. As EaselJS is the framework I know the most, I won't be impartial. It's up to you to test the other one and make your own opinion.

Some beginners' tutorials

Well, as a pure megalomaniac I am, let me start by sharing you my own tutorials. 1 year ago, I had fun porting an XNA C# game into HTML5/JavaScript thanks to EaselJS. I've then decided to write 3 first tutorials to share this experience:

  • HTML5 Gaming: animating sprites in Canvas with EaselJS
  • HTML5 Gaming: building the core objects & handling collisions with EaselJS
  • HTML5 Platformer: the complete port of the XNA game to <canvas> with EaselJS

Several months later, I've done 3 others articles enhancing/extending the same game:

- Tutorial: how to create HTML5 applications on Windows Phone thanks to PhoneGap where I'll show you how to port the same game on Windows Phone thanks to PhoneGap/Cordova. But you will be able to follow the same instructions for your Android or iOS device.
- Modernizing your HTML5 Canvas games Part 1: hardware scaling & CSS3 where we'll use CSS3 3D

Transform, Transitions & Grid Layout to enhance the gaming experience
- Modernizing your HTML5 Canvas games Part 2: Offline API, Drag'n'drop & File API where we will enable playing to the game in offline mode. You will be even able to create your own levels and drag'n'drop them directly into the game.

After following them, you'll build this game:

Well, logically, thanks to these 6 tutorials, you should be able to write your own HTML5 game whatever the browser or device you're targeting.

You'll find also a lot of simple demo to understand and great tutorials on the EaselJS website: http://www.createjs.com/#!/EaselJS as well as on each frameworks' website mentioned above.

You'll find more generic tutorials on those sites also:

To conclude, I'd like to recommend you 2 more "advanced" articles but very instructive to read. The first one is written by David Catuhe from Microsoft: Unleash the power of HTML 5 Canvas for gaming . He will share with you some optimization he has found while working on a "demo" like the one we were writing in the "demo scene". The tips found could bring you some ideas for your own HTML5 games. The second one is written again by Boris Smus from Google: Improving HTML5 Canvas Performance and it contains ton of good advices.

Some interesting online working games & experience feedbacks

Again, this is my personal favorites. You will probably find other cool examples on the web to share. Whatever the game you'll like, it is interesting to analyze how the developers made them. Thanks to the magic of the web, you just have to right-click & "view source". Even if the code will be probably minified, you can still learn a couple of interesting things by looking at the global architecture of the game.

Let's start by some productions using the EaselJS framework. The first one was Pirates Love Daisies written by Grant Skinner:

Grant has started his EaselJS framework while building this HTML5 game.

Windows 8 note: you'll notice you'll find the very same game working inside Windows 8 in the Windows Store here: Pirates Love Daisies for Windows 8 . Indeed, if you have a HTML5 game working fine inside IE9 or IE10, building the Windows 8 version is almost only doing a simple copy… and paste! The game will then directly works inside the Metro experience. But to make a real good Windows 8 game, you will have also to pay attention to the unique Windows 8 experience we're building. This is described here: Designing great games for Windows

Another game using EaselJS is BKOM ROBOT GAME which uses 3D sprites I love:

The 2 most currently famous HTML5 games are of course Angry Bird (which uses the Box2D library I was mentioning above):

And Cut The Rope:

You'll find also a Windows 8 version of it in the Windows Store here: Cut The Rope for Windows 8

It was very simple to port into Windows 8. Here is the process:

1 – Copy/Paste the Web version into a HTML5 Metro Style App project for Windows 8 2 – Add support for touch 3 – Add support for the snapped view and pause the game 4 – Build some High Resolution assets (1366×768 & 1920×1080) to propose the best experience for all the incoming Windows 8 tablets & PC.

I also love the story around "Cut The Rope". It's very interesting to read. This was a successful game written in Objective-C for the Apple iOS devices. It was ported into HTML5/Canvas and the developers who made this detail their feedback in this article: Cut The Rope – Behind the scenes . Have a look, you'll probably learn some interesting points. I've also add pleasure reading this experience feedback: Wooga's HTML5 Adventure

At last, here is a list of 40 more or less good HTML5 games: 40 Addictive Web Games Powered by HTML5 with some other available also here: HTML5games.com

I now hope that all these resources will help you to build your own HTML5 game. If you're doing so and/or if you have any suggestions to provide on good frameworks/tutorials/concepts you'd like to share, please share your thoughts with me!

About the Author

David Rousset is a Developer Evangelist at Microsoft, specializing in HTML5 and web development. Read his blog on MSDN or follow him @davrous on Twitter.

Sponsors

Professional Web Icons for Your Websites and Applications

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions