8

Gaming API and Sound

The creation of the raw frames follows these standards:

Frames must be equally sized, all being of the frame width (fWidth) and height (fHeight) defined in the constructor parameters. They may be laid out in the image horizontally, vertically, or as a grid. The width of the source image must be an integer multiple of the frame width. The height of the source image must be an integer multiple of the frame height.

The frames in the source image will have raw frame numbers as follows:

The frames are numbered like words are read on a page; left-to-right, then top- to-bottom. The top-left frame is numbered 0. If there is a frame to its right, this frame is numbered 1, and so on, across the first row of frames. If there is a second row of frames, the number of the left-most frame in this row is one greater than the right-most frame in the preceding row. The table below is a diagrammatic depiction:

0

1

. . .

N – 1

 

 

 

 

N

N + 1

. . .

2N – 1

 

 

 

 

2N

2N + 1

. . .

 

 

 

 

 

. . .

. . .

. . .

. . .

 

 

 

 

(M – 1) * N

((M-1)* N ) + 1

. . .

(M * N ) – 1

 

 

 

 

So the total number of frames is M * N, where:

N = (image width) / (frame width)

M = (image height) / (frame height)

At the time of creation, all Sprites have a default frame sequence corresponding to the raw frame numbers. This can be modified with setFrameSequence(). At construction time, the Sprite's position will be set to (0,0), the depth will be set to 0, and the Sprite will be visible. The Sprite shall behave as if the image used in creation were cached. If a mutable image is used to create the Sprite, the Sprite's appearance should not reflect changes to mutable source image.

public Sprite(Sprite s) – Creates a new Sprite from another Sprite. Create a copy of a Sprite. All attributes (raw frames, position, frame sequence, current frame, visibility) of the source Sprite should be reflected in the new Sprite. Any subsequent updates to the source Sprite after the creation of the second Sprite should not be reflected in the second Sprite.

Sprite Methods

The Sprite class implements the following methods:

public void setPosition(int x, int y) – Set Sprite's x,y position. The x, y position is relative to whatever object the sprite is associated with or drawn on.

57

Page 57
Image 57
Motorola C550, C450, C370 technical manual Sprite Methods