Game Development Reference
In-Depth Information
the JavaFX SceneGraph. At that point, the method is finished, and will then return con-
trol to the calling entity.
If an Actor object of that type is found in the CURRENT_CAST List<Actor> Ar-
ray, a return; statement will be called to immediately exit the method, and return con-
trol to the calling entity. This means that the statements at the end of the for() loop,
which add a new Actor object of that type to the cast, as well as adding a new Actor
object to the JavaFX Scene Graph root object, will not be executed.
This return; statement is a central component to making this method work, be-
cause if any Actor object of that type exists, a duplicate one will not be added to the
List<Actor> Array, which would cause an error to occur. This is a great way to make
sure that we only use one Node for each type of Projectile and Enemy object, which al-
lows us to optimize both memory and processor overhead. The Java 8 programming
structures for all three of these methods is quite similar, and can be seen in Figure
17-48 . The three private void method bodies should look like the following:
private void loadBullet() {
for (int i=0;
i<invinciBagel.castDirector.getCurrentCast(). size() ; i++)
{
Actor object =
invinciBagel.castDirector.getCurrentCast(). get(i) ;
if( object.equals (invinciBagel. iBullet )) {
return;
}
}
invinciBagel.castDirector. addCurrentCast (invinciBagel.iBullet);
invinciBagel.root. getChildren().add (invinciBagel.iBullet.spriteFrame);
}
private void loadCheese() {
for (int i=0;
i<invinciBagel.castDirector.getCurrentCast(). size() ; i++)
{
Actor object =
invinciBagel.castDirector.getCurrentCast(). get(i) ;
if( object.equals (invinciBagel. iCheese )) {
return;
}
 
Search WWH ::




Custom Search