Motorola C550 ユーザーズマニュアル

ページ / 86

Gaming API and Sound  
 
53 
collidesWithAnyTile(Sprite) and collidesWithTiles(int, int, int, int, Sprite, boolean) 
complement each other. Sprite 
s
 does not have to have been added to the PlayField. 
The collision detection will proceed as if the Sprite is on the PlayField. That is, its 
location will be treated as relative to the origin of the PlayField's coordinate system. 
• 
public boolean collidesWithAnyTile(Sprite s)
 throws 
NullPointerException
 – Check for Sprite collision with PlayField tiles. 
Return true if the Sprite overlaps with a cell that contains a tile (i.e. a cell containing a 
non-zero tile index). Sprite 
s
 does not have to have been added to the PlayField. The 
collision detection will proceed as if the Sprite is on the PlayField. That is, its location 
will be treated as relative to the origin of the PlayField's coordinate system. 
• 
public boolean collidesWithTiles(int col, int row, int width, int height, Sprite s, 
boolean pixelLevel) throws NullPointerException, ArrayIndexOutOfBoundsException 
– Check for Sprite collision with a region of PlayField tiles. It returns true if the Sprite 
overlaps with a cell in the defined region that contains a tile (i.e. a cell containing a 
non-zero tile index). If 
pixelLevel
 is true, this method will report a collision only 
when opaque Sprite pixels overlap opaque tile pixels. This method complements the 
collidesWithAnyTile(Sprite) method by letting the programmer focus their search and 
find specific tiles or regions of collision. This is similar to how 
Sprite.collidesWith(Sprite, boolean) complements collidesWithSprites(Sprite). The 
method parameters are the following: 
row
 - Row of top-left cell for collision check 
region; 
col
 - Column of top-left cell for collision check region; 
height
 - Height, in 
rows, of area for collision check; 
width
 - Width, in rows, of area for collision check; 
s
 - Sprite to check for collision; and 
pixelLevel
 - Boolean indicating whether 
collision detection should be done at a pixel level instead of simply as boundary 
checks. 
• 
public void setStaticTileImage(int staticTileIdx, 
Image img, int x, int y)
 throws 
NullPointerException
ArrayIndexOutOfBoundsException
 – Modify the image associated with 
a static tile. Replace the image currently associated with a static tile with a new image 
of the same size. New static tile image will be extracted from the image passed in, 
starting from pixel 
(x, y)
 in the new source image and extending for getCellWidth() 
pixels horizontally and getCellHeight() pixels vertically. As at tile set creation time, if a 
mutable source image is used, behavior of the tile set should be as if the new image 
were cached. Updates to the mutable source image will not cause a change in the 
appearance of the tile image. 
• 
public void setStaticTileSet(Image img, int tWidth, 
int tHeight)
 throws 
NullPointerException
IllegalArgumentException
 – Replaces the current static tile set with a 
new static tile set. See the constructor PlayField(int, int, Image, int, int) for information 
on how the tiles are created from the image. If the new static tiles have the same 
dimensions as the previous static tiles, the view window will be unchanged. If the new 
static tiles have different dimensions than the previous static tiles, the view window 
will be reset to the construction default, i.e. the entire grid dimension. If the new static 
tile set has as many or more tiles than the previous static tile set, then the animated 
tiles will be unchanged, and the contents of the PlayField grid will be unchanged. If 
the new static tile set has less tiles than the previous static tile set, then the PlayField 
grid will be reset to completely empty, and All animated tiles will be deleted.