Game Development Reference
In-Depth Information
CollisionResult closest =
results.getClosestCollision();
Tip
It's a good idea to have a look at the CollisionResults class as well as
CollisionResult , as these classes already keep track of many useful things
that will save valuable coding time.
14. After this, we can parse through our selectable list to see whether the spa-
tial that was clicked on has any of the items in the list. If it is, we call the fol-
lowing code:
spatial.getControl(SelectableControl.class).setSelected(true);
15. Depending on the requirements, we might want to deselect all other spatials at
this point. If we're using nodes, we might also need to see whether it is any of the
spatial's children that were hit by the ray as well.
16. To test this, we can use the same class used in the previous recipe, with a few ad-
ditional lines.
17. First of all, we need to create and attach SelectAppState as follows:
SelectAppState selectAppState = new SelectAppState();
stateManager.attach(selectAppState);
18. Create SelectableControl and something that can be used as a marker (in
this case, it will be a simple Quad).
19. Lastly, we need to add SelectableControl to our Jaime model, and then
add Jaime as a selectable to AppState as follows:
jaime.addControl(selectableControl);
selectAppState.addSelectable(jaime);
20. If we now run the example and click on Jaime, the Quad should be rendered near
his feet.
Search WWH ::




Custom Search