Book Image

Libgdx Cross-platform Game Development Cookbook

Book Image

Libgdx Cross-platform Game Development Cookbook

Overview of this book

Table of Contents (20 chapters)
Libgdx Cross-platform Game Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing a deferred raycaster


The Querying the world recipe is a good proof of the potential of raycasting within a physics game environment. However, sometimes you might perform too many simultaneous queries within the same game loop iteration, so the CPU is not able to process them fast enough and makes a small freeze visible on the screen.

A solution would be to implement a queue of raycast queries, ordered by priority, with the particularity of having a limited time per frame to dispatch as much as it can, keeping the rest for future iterations. The higher the priority, the sooner it will be executed.

Getting ready

In order to keep things tidy, the code will be split into two files:

  • RayCastManager.java to implement the deferred raycaster

  • Box2DDefereedRaycasterSample.java shows a practical usage case of the aforementioned class

If you do not feel comfortable with world queries, I strongly suggest you to go back and review the Querying the world recipe.

How to do it…

This recipe will not...