Java Reference
In-Depth Information
Table 14-2.
Collision Detection with Sprite
Target
Intersecting Rectangle
Pixel Level
Sprite
Compares collision rectangles
Compares pixels inside the collision
rectangles
TiledLayer
Compares the
Sprite
's collision
rectangle and tiles in the
TiledLayer
Compares pixels inside the
Sprite
's
collision rectangle with pixels in the
TiledLayer
Image
Compares the
Sprite
's collision
rectangle and the
Image
's bounds
Compares pixels inside the
Sprite
's
collision rectangle with pixels in the
Image
Copying Sprites
Sprite
includes a copy constructor:
public Sprite(Sprite s)
This is more powerful than you might think. It creates a new
Sprite
with all of the attributes of
the original, including
•
Source image frames
•
Frame sequence
•
Current frame
•
Current transformation
•
Reference pixel
•
Collision rectangle
Putting It All Together
QuatschCanvas
, shown in Listing 14-2, is an example that showcases many of the features of the
Game API. Although it looks long, it's broken into manageable methods and demonstrates
quite a few features of the Game API:
•
Using an animation loop in
GameCanvas
Polling for key state using
GameCanvas
•
•Using a
LayerManager
to maintain multiple layers
Creating a
Sprite
and
TiledLayer
s
•
Animating a
Sprite
, including changing frame sequences and transformations
•
Using an animated tile in a
TiledLayer
•
Search WWH ::
Custom Search