Game Development Reference
In-Depth Information
Figure 14-7 . Add the super() constructor method call inside of the Prop() constructor, to get rid of the error highlight
The next thing that we will need to do, to position the fixed sprite, using the xLoca-
tion and yLocation values that are passed into the constructor method, is to use the
.setTranslateX() and .setTranslateY() methods. Remember that you utilized these meth-
ods in Chapter 12 in the .moveInvinciBagel() method. We'll use these again, in this
Prop() constructor method, to position these fixed sprites on the Stage where your con-
structor method parameters instruct the object constructor to locate them on the screen.
It is important to remember that because of the work we did in Chapter 8 that the
Actor superclass's Actor() constructor method already performs the iX=xLocation;
and iY=yLocation; sprite iX and iY property setting for us. Thus, all that we have to
do in the Prop() constructor method is to call
spriteFrame.setTranslateX(xLocation); and
spriteFrame.setTranslateY(yLocation); inside of the constructor meth-
od, and after our super() constructor method call. Notice in the code that the xLocation
and yLocation variables are utilized in both the super() constructor method call to set
the iX and iY properties for the Prop Actor as well as inside the .setTranslateX() and
.setTranslateY() method calls, to position the fixed sprites on the Stage during the Prop
object instantiation, so that we do not have to do this somewhere else in our code. The
Java code for the class, and constructor method, will look like the following:
package invincibagel;
import javafxscene.image.Image;
public class Prop extends Actor {
 
Search WWH ::




Custom Search