28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8 ■ Creating Your Actor Engine: Design the Characters for Your Game and Define Their Capabilities<br />

Creating an Actor Superclass: Fixed Actor Attributes<br />

Let’s get down to scratch coding our public abstract Actor class that will be the foundation for all sprites we will be<br />

creating for the game during this book. I won’t revisit how to create a new class in NetBeans (see Figure 7-2) as you’ve<br />

already learned that in Chapter 7, so create an Actor.java class, and declare it using public abstract class Actor and<br />

place the first five lines of code at the top of the class, declaring a List named imageStates, and creating a<br />

new ArrayList object, as well as an ImageView named spriteFrame, an SVGPath named spriteBound, and double<br />

variables iX and iY. Make all of these protected, so that any subclasses can access them, as is shown in Figure 8-4.<br />

You’ll need to use the Alt-Enter work process for the red error underlining relating to the import statements you will<br />

need for the List class (object), ArrayList class (object), Image class (object), ImageView class (object), and SVGPath<br />

class (object). Once NetBeans writes these for you, the dozen or so lines of code declaring the List ArrayList,<br />

spriteFrame ImageView, SVGPath collision Shape object and double variables containing the sprite’s X and Y location<br />

should look like the following <strong>Java</strong> class structure:<br />

package invincibagel;<br />

import java.util.ArrayList;<br />

import java.util.List;<br />

import javafx.scene.image.Image;<br />

import javafx.scene.image.ImageView;<br />

import javafx.scene.shape.SVGPath;<br />

public abstract class Actor {<br />

protected List imageStates = new ArrayList();<br />

protected ImageView spriteFrame;<br />

protected SVGPath spriteBound;<br />

protected double iX;<br />

protected double iY;<br />

}<br />

Figure 8-4. Create a New Class in NetBeans, name it public abstract class Actor, and add in the primary Actor variables<br />

168

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

Saved successfully!

Ooh no, something went wrong!