Our News RSS

HTML5 Canvas for mobile devices

From joshy.org, some good principles about how to optimize HTML5 canvas for mobile devices.

Quoted verbatim here:

  • Now, let’s talk about mobile devices and optimization. There is no mobile version of canvas, there’s just canvas. It’s the same API on desktop and mobile devices. Mobile devices are sometimes missing features, however, and are usually slower; but the same could be true on older desktops and browsers. So whenever you are making a canvas app it’s important to consider performance and different ways to optimize your code.
  • The general mantra for performance is draw less.
  • Don’t draw hidden things. If you have four screens of information but only one is visible at a time, then don’t draw the others.
  • Use images instead of shapes. If you have some graphic that won’t ever change or be scaled, then consider drawing it into an image at compile time using something like photoshop. In general images can be drawn much faster to the screen than vector artwork. This is especially true if you have some graphic that will be repainted over and over again like a sprite in a game.
  • Cache using offscreen canvases. You can create new instance of the canvas object at runtime that aren’t visible on screen. You can use these offscreen canvasas as a cache. When your app starts draw graphics into the offscreen canvas then just copy that over and over again to draw it. This gives you the same speed as using images over shapes, but you are generating these images at runtime and could potentially change them if needed.
  • Image stretching. Since we are using images for lots of things already, consider stretching them for effects. Most canvas implementations have highly optimized code for scaling and cropping images so it should be quite fast. There are also several versions of drawImage that let you draw subsections of an image. With these apis you can do clever things like caching a bunch of sprites into a single image, or wildly stretching images for funky effects. [screenshots]
  • Only redraw the part of the screen you need. Depending on your app it may be possible to just redraw part of the screen. For example, if I have a ball bouncing around I don’t need to erase and redraw the entire background. Instead I just need to redraw where the ball is and where it was on the previous frame. For some apps this could be a huge speedup.
  • Draw fewer frames Now that you are drawing as little per frame as possible try to draw fewer frames. To get smooth animation you might want to draw 100fps, but most computers max out at a 60fps screen refresh rate. There’s no point in drawing more frames because the user will never see them. So how do you sync up with the screen refresh? Mozilla and WebKit have experimental apis to request that the browser call your code on the next screen refresh. This will replace your call to setInterval or setTimeout. Now the browser is in charge of giving you a consistent framerate, and it will ensure you don’t go over 60fps. It can also do smart things like lowering the framerate if the user switches to a different tab. Mobile browsers are starting to implement this as well so background apps will be throttled back, saving on battery life.
  • The best way to draw less is to not draw it at all. If you have a static background then move it out of canvas and draw it with just an image in the browser. You can make the background of a canvas transparent so that a background image will show through. If you have large images to move around you may find they move faster and smoother by using CSS transitions rather than doing it with javascript in the canvas. In general CSS transitions will be faster because they are implemented in C rather than JS, but your mileage may vary, so test test test. Speaking of which: Chrome and Mozilla have great tools to help you debug and test your JavaScript. [names? examples?]
  • Pixel aligned images. One final tip, in some implementations images and shapes will draw faster if they are draw on pixel boundaries. Some tests show a 2 to 3x speedup [verify] on the ipad canvas impl if you pixel align your sprites.  http://jsperf.com/drawimage-whole-pixels http://sebleedelisle.com/2011/02/html5-canvas-sprite-optimisation/
This is just the mobile section, read the full article at joshy.org.

20 HTML5 Sites to Inspire You

During 2010 we heard a lot about HTML5 and its possibilities and capabilities. The new updated version of the web standard HTML was at the spotlight and everyone was pretty interested in learning more about its features and techniques. HTML5 has lots of new and interesting tags that allow you to easily incorporate videos, use drag and drop and do hundreds of cool effects and interactions. Here we will show a list with 20 examples of websites using HTML5 and their developers. Almost all examples are developers/designers pages, what show us that several professionals are already adepts of this new trend.

We also checked how are the websites reacting in mobile versions, we tested the iPhone and Android (G1) environment. The Android was tested via emulator, so maybe some results are not 100% accurate.

Colosseo Type

Beautiful background image and hover effects.

html501

Designer/developer: Cameron Moll.
iPhone performance: everything looks good, the video from the header was removed at the mobile version.
Android performance: everything looking good, even the video.

Information Highwayman

Simple and elegant layout with nice hover effects.

html502

iPhone performance: text look good and centralized but the background looks a bit out of place.
Android performance: everything ok

Jeroen Homan

Super clean and beautiful layout.

html503

Designer/developer: Jeroen Homan.
iPhone performance: main content and images are ok, footer is not loading properly.
Android performance: everything looking good.

Keyzo IT Solutions

Nice image transitions and subtle menu hover effects.

html504

Designer/developer: Keyzo IT Solutions.
iPhone performance: works fine but could make more use of media queries instead of loading a static version to adjust the screen size.
Android performance: looks good.

Rui Mollar

Clean and minimal layout with beautiful hover effects.

html505

Designer/developer: Rui Mollar.
iPhone performance: also looks good but loads in the static size of the screen.
Android performance: ok

Superhug

Subtle shadow when hovering menus and a nice image showcase and transitions.

html506

Designer/developer: Superhug.
iPhone performance: looks good and works fine.
Android performance: looks fine.

Ricardo Saavedra

Nice effect on header’s menu and framed links with hover effects.

html507

Designer/developer: Ricardo Saavedra.
iPhone performance: looks good, also adjusted to fit the screen.
Android performance: everything working.

Yellowhammer Creative

html508

Designer/developer: Yellowhammer Creative.
iPhone performance: perfect!
Android performance: also perfect!

fellabinaryreviews

Nice header and search box fade effect. Also nice text shadows.

html509

Designer/developer: TheFella.
iPhone performance: great!
Android performance: also great!

Cazinc Web Development

Great colors, design, navigation, images disposition and simplicity.

html510

Designer/developer: Cazinc Web Development.
iPhone performance: perfect!
Android performance: yeah, perfect here too!

Deafpigeon

Beautiful header background images and hover effect on menus.

html511

Designer/developer: Planetperki.
iPhone performance: looks and works good, even the background transitions.
Android performance: also good.

Planetperki

Really nice and smooth image transitions and hover effects.

html512

Designer/developer: Planetperki.
iPhone performance: looks and works good, even the background transitions.
Android performance: same here.

Michael Acevedo

Nice single page layout with vertical slider navigation, cool hover effects and images disposition.

html513

Designer/developer: Michael Acevedo.
iPhone performance: perfect!
Android performance: also perfect!

Ben the Bodyguard

Awesome user interaction at navigation. Attention to details and beautiful interface.

html514

Designer/developer: Nerd Communications.
iPhone performance: great!
Android performance: not working at all, probably because it’s an iPhone / iPod Touch app. ;)

Julien Etienne

Really nice transitions and background effects.

html515

Designer/developer: Julien Etienne.
iPhone performance: not loading properly, broken background and text.
Android performance: apparently everything works fine.

Vision 18

Single page design with nice vertical slider navigation and effects. Good user interaction.

html516

Designer/developer: Vision 18.
iPhone performance: perfect!
Android performance: also perfect!

Tablet Tennis

All HTML5 game.

html507

Designer/developer: Michiel Van den Anker.
iPhone performance: not working.
Android performance: not working.

HTML5 Adventure Calendar

Really nice shadow effects and image/information boxes.

html518

Designer/developer: ZingChart.
iPhone performance: works good, the only effect missing is the shadows, everything else is ok.
Android performance: works fine.

Maze

Another HTML5 game.

html519

Designer/developer: Kate.
iPhone performance: not working.
Android performance: not working.

HTML5 Readiness

Clean and elegant layout where we hover around to check browser readiness for HTML5 & CSS3 features. Really nice interaction and effects.

html520

Designer/developer: Paul Irish and Divya Manian.
iPhone performance: not working. The site loads broken and you can’t navigate it properly.
Android performance: looks good but doesn’t have the same interaction and effects.

Source:

HTML5 Gallery
101 Best HTML5 Sites

LimeJS HTML5 framework for games on web and mobile

LimeJS launched a new platform for building HTML5 games. The examples they show work well but are fairly simple puzzle like games. You can see them here:

Roundball
Zlizer

EasleJS libraries for HTML5 on web and mobile

EasleJS just announced a new Javascript library for building HTML5 games or apps.  It’s built by a development firm gskinner but they are releasing under the MIT license for unrestricted commercial and noncommercial re-use.

It’s only v1, so hopefully we’ll see more good stuff from them.  They claim support for iOS and Android, but most of the current samples don’t function particularly well on the mobile devices we tested.

Here’s a screenshot of their moving rats sprite sheet demo.  Simple but nice on Chrome:

Zynga launches HTML5 game Mob Wars

Like many casual gaming companies, Zynga is making a big bet on HTML5 games. Their release of Mob Wars is their first major foray into the field.

The game works in all major smartphone browsers we tested, including web. However, the simplicity of this ‘text-based’ game means it’s not taking advantage of much interesting functionality in HTML5. It also allow registration only through a Facebook login, seemingly defeating the point of Zynga’s move to become more independent of Facebook for their distribution.

You can play the game at m.mafiawars.com.

ImpactJS HTML5 Mobile Game Engine

If you want to build 2D retro games for any mobile device, the ImpactJS HTML5 engine might be a good fit for you.

ImpactJS gains immediate credibility because the developer released games built on top of it that are functional on iPhone and Android browsers. Few of the other viable 2D game platforms work across HTML5 mobile devices yet.

If you want to read a debate about JS game engines, check out HackerNews.

Recent News:

Twitter:

  • Top 20 HTML5 sites: http://goodscreens.com/2011/02/20-html5-sites-to-inspire-you/

  • Comscore released their report on the 2010 U.S. Digital Year in Review. Lots of good metrics on the mobile...

  • Apple is getting into the game of html5-based mobile toolkits with their release of iAd Producer.

  • EasleJS just announced a new Javascript library for building HTML5 games or apps.

Who are we?

We are people who like building things with mobile technology.