Faster Canvas Picking

Colt “MainRoach” McAnlis, Developer Advocate, Google
  • Colt McAnlis
  • Petter Lubbers
  • Brandon Jones
  • Duncan Tebbs
  • Andrzej Manzur
  • Sean Bennett
  • Florian d’Erfurth
  • Bruno Garcia
  • Shun Lin
  • Ivan Popelyshev
  • Jason Gauci
  • Jon Howard
  • Ian Ballantyne
  • Jesse Freeman
  • Takuo Kihira
  • Tyler Smith
  • Don Olmstead
  • John McCutchan
  • Chad Austin
  • Andres Pagella
Chapter

Abstract

If you’re writing a 2D game in HTML5, chances are that you’ll want the user to have the ability to pick an object on the screen. More specifically, at some point, the user will need to select some item on the screen, or in your game, which may represent part of the world. We call this “picking” as the user is selecting what object they are interacting with. Consider, for instance, your standard social time-management game. The user is presented with a 2.5D play area where bitmaps (or “sprites”) are rendered with some perspective distortion on the screen. For the more advanced users, you can quickly saturate the play area with these sprites, often stacking many of them together, only leaving a few pixels visible between overlapping objects. In this environment, determining the picking result of a mouse click is quite difficult. The canvas API doesn’t provide any form of pixel-based selection and the large number of objects makes it difficult to brute-force the technique. This section will cover how to address performance and accuracy problems in canvas picking using a few old-school techniques that most of us have forgotten about.

Keywords

Convex Hull Memory Footprint Pixel Data Play Area Perspective Distortion 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Copyright information

© Colt McAnlis 2014

Authors and Affiliations

  • Colt McAnlis
    • 1
  • Petter Lubbers
    • 1
  • Brandon Jones
    • 1
  • Duncan Tebbs
    • 1
  • Andrzej Manzur
    • 1
  • Sean Bennett
    • 1
  • Florian d’Erfurth
    • 1
  • Bruno Garcia
    • 1
  • Shun Lin
    • 1
  • Ivan Popelyshev
    • 1
  • Jason Gauci
    • 1
  • Jon Howard
    • 1
  • Ian Ballantyne
    • 1
  • Jesse Freeman
    • 1
  • Takuo Kihira
    • 1
  • Tyler Smith
    • 1
  • Don Olmstead
    • 1
  • John McCutchan
    • 1
  • Chad Austin
    • 1
  • Andres Pagella
    • 1
  1. 1.CAUS

Personalised recommendations