8
Gaming API and Sound
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
•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
•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.
53