Using Input Queues

Earlier, the chapter discussed how massive amounts of user input can freeze a game and cause it to stall. You can address this possibility with the very handy InputObject class. Basically, you’re trying to limit the strain that is put on your main thread when input events happen. Recall that Figure 3-2 showed how you hold input events before responding to them. This is exactly what you do here. Instead of waiting to lock up the entire thread, you do the majority of the work in the background.

This system was originally introduced to me by Robert Green, and it’s so efficient and simple that I have used it ever since. (You can read Robert’s blog about Android development and other musings at www.rbgrn.net/.) An ArrayBlockingQueue ...

Get Beginning Android Tablet Games Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.