HTML and CSS Reference
This chapter has discussed a set of techniques which, when used independently, can decrease processing time for
picking and increase precision at the same time.
Industrial strength implementations of this type of code, however, will find the right and smart way to combine
these techniques for the best results. Before you ship this technique in your title, consider some of the following
For example, having a separate spatial grid for dynamic vs. static objects will help create
early-out logic for frequently updating objects that tend to complicate your binning selection.
Only allow visible objects to be pickable. It doesn't help your performance to check objects
which are off-screen and not visible to the user, especially in large levels, where the majority of
objects are outside the view bounds.
Per sprite, define what type of picking collision it should use. Some images are fine with
box-only picking; for others, convex hull should be enough; and for the rare few that need it,
use pixel-perfect solutions.
Don't forget that as your scene changes, so does the complexity of picking. For example, a tall
building may hide multiple objects behind it, which may not need to be selectable any longer.
Updating your scene representation to take this into account is ideal.
Animated images complicate picking quite easily. Your art chain will need some way to
output pixel/hull/bounding information per frame of animation and update your sprite
representation to produce picking information for the current frame of the animation.
Transforms and scales of bitmaps also complicate things. Most of the simplistic logic
presented in this article quickly becomes error-prone when you rotate and scale bitmaps.
One of the most annoying results of picking is pick complexity, or rather when the user clicks
on objectA, meaning to get to objectB below it. If this is a common complaint, consider adding
code paths to allow a multi-click within a tolerance (so if the user clicks the same location
twice) to select the second or third stacked object. (In this article I only discussed returning
the CLOSEST object to the pick.)