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 raycasterBox2DDefereedRaycasterSample.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...