Game Development Reference
In-Depth Information
This is what I term
sprite registration
, and involves
positioning
the different sprite
states optimally relative to each other.
Some examples of sprite registration between sprite frames that will be used with
each other can be seen in
Figure 8-3
. For instance, the starting to run imageStates[1]
sprite should start its run cycle with the same foot position as a standing (or waiting)
imageStates[0] sprite, as seen on the left side of
Figure 8-3
.
Also, the running im-
ageStates[2] sprite should keep its body portion as still as possible, relative to the im-
ageStates[1] starting to run sprite. A preparing to land imageStates[6] sprite should
change foot positioning realistically relative to the landed imageStates[7] sprite.
Figure 8-3
.
Sprite registration (alignment) to make sure the transition motion is smooth
What you want to do to optimize sprite registration, relative to all of the other
sprites, is to put all of your digital image sprites into the same square 1:1 aspect ratio
resolution image format, and place them all in
layers
in a digital image compositing
software package, such as GIMP or Photoshop. Then use the
move tool
and
nudge
(single pixel movements using arrow keys on keyboard) each sprite into position, relat-
ive to whichever two layers you have visibility (toggled on/off using the eye icon on
the left of each layer) turned on for. The result is shown in
Figure 8-3
.
CreatinganActorSuperclass: Fixed Act-
or Attributes
Let's get down to scratch coding our public abstract Actor class that will be the founda-
tion for all sprites we will be creating for the game during this topic. I won't revisit
how to create a new class in NetBeans (see
Figure 7-2
) as you've already learned that
Actor
and place the first five lines of code at the top of the class, declaring a
List<Image> named
imageStates
, and creating a
new ArrayList<>
object, as well as
an ImageView named
spriteFrame
, an SVGPath named
spriteBound
, and double