−
Using Sprite
The example below creates two Sprites (bullet and tank) and tests collisions between
them. When there are no lives left, the game finishes.
The following is a code sample to show implementation of using sprites:
Sprites
try {
Sprite bullet = new Sprite(Image.createImage("bullet.png");
Sprite tank = new Sprite(Image.createImage("tank.png");
} catch (Exception e) {
// any image can't be loaded
}
Boolean isGameOver= False;
int lifes= 3; // The number of lives is 3
while(!isGameOver) {
// verifies the collision between the two sprites
if(tank.collidesWith(bullet,false)) {
lifes--;
// If there are no more lifes, the game is over
if(lifes == -1) {
isGameOver = true;
}
}
}
FileFormatNotSupportedException
The
FileFormatNotSupportedException
when a
or the size of the data is larger than the size of the internal buffers. The
FileFormatNotSupportedException
java.lang.RuntimeException
Any custom frame sequence will be deleted and the frame sequence will revert
to the default frame sequence for the new frame set (all frames in the frame set,
left-to-right then top-to-bottom).
or
SoundEffect
BackgroundMusic
is an exception which will be thrown
format is not supported by the platform
extends the
class.