28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10 ■ Directing the Cast of Actors: Creating a Casting Director Engine and Creating the Bagel Actor Class<br />

Figure 10-13. Code a public Bagel() constructor method that calls a super() constructor method (from Hero superclass)<br />

The code to implement the (currently) empty .update() method uses a <strong>Java</strong> @Override keyword, and once it is in<br />

place the error will disappear, and the code will be error-free, as seen in Figure 10-14. The code looks like this:<br />

@Override<br />

public void update() { // empty method structure }<br />

Figure 10-14. Add a public void .update() method to override the public abstract void update method in the Hero class<br />

Notice at the top of Figure 10-14 that you will have to add the import javafx.scene.image.Image; code statement<br />

in order to be able to use the Image... annotation in your public Bagel() constructor method parameter list.<br />

Just to be thorough, let’s override a public Boolean .collide() method as well, so that we have it in the Bagel<br />

class. You may be wondering why NetBeans did not give us an error in Figure 10-14 when we did not add the .collide()<br />

method to the Bagel class. As you can see in Figure 10-15, which shows the public abstract Hero class, we didn’t make<br />

the .collide() method a public abstract method, like we did with the .update() method. This is why NetBeans 8 did not<br />

generate any error highlighting, because we’re not required to implement the .collide() method in all Hero subclasses.<br />

www.it-ebooks.info<br />

225

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!