Artenus 2D Framework
Artenus Reference

Provides a grid of texture blocks. It is intended for platform or map based games. You can create a large grid and add it to the scene as a normal sprite. Only the portion of the grid that is visible will be rendered. Use this sprite for level maps.

Note that this class is subject to revision or removal in the future. It is NOT yet deprecated. Support for platform-based games is currently being revised and a faster and more robust framework will be introduced in future versions.

public final class GridSprite
extends SpriteEntity

Field Summary

Fields inherited from com.annahid.libs.artenus.graphics.sprites.SpriteEntity

Constructor Summary

Modifier and TypeConstructor and Description
public GridSprite(int resourceId, float frameWidth, float frameHeight, float margin, int cols, int rows)
Creates a GridSprite using a image resource id and block parameters.

Method Summary

Modifier and TypeMethod and Description
public floatgetAlpha(int col, int row)
Gets the transparency value for the given grid block.
public intgetColumns()
Gets the number of columns for this grid.
public intgetFrame(int col, int row)
Gets the current frame (image block index) of the given grid block.
public floatgetHeight()
Gets the assigned height for this grid.
public intgetRows()
Gets the number of rows for this grid.
public floatgetWidth()
Gets the assigned width for this grid.
public voidrender(RenderingContext context, int flags)
Renders the visual content.
public voidsetAlpha(int col, int row, float alpha)
Sets the transparency value of the given grid block.
public voidsetFrame(int col, int row, int frame)
Sets the current frame of the given grid block.
public voidsetVisibleRegion(float startX, float startY, float endX, float endY)
Sets the visible area within the grid block.

Methods inherited from com.annahid.libs.artenus.graphics.sprites.SpriteEntity

Methods inherited from java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

GridSprite
public  GridSprite(
    int resourceId,
    float frameWidth,
    float frameHeight,
    float margin,
    int cols,
    int rows
)
Creates a GridSprite using a image resource id and block parameters. Like Sprite, this class supports SVG images with raw resource type as well as images normally supported by the android platform. It is recommended to provide SVG images for better scaling in different screen resolutions. The image is cut out into frames using the given block width and height.
Parameters:
resourceIdThe resource identifier for the image
frameWidthThe block width
frameHeightThe block height
marginThe margin for each image block. It is recommended to have a transparent margin for each block to avoid color mixing. This parameter specifies the size of this margin. Grid blocks are squeezed together with this parameter to diminish the transparent margin.
colsThe number of columns for this grid
rowsThe number of rows for this grid

Method Detail

getAlpha
public float getAlpha(
    int col,
    int row
)
Gets the transparency value for the given grid block.
Parameters:
colThe column number of the block
rowThe row number of the block
Returns:
The transparency (alpha) value
getColumns
public int getColumns()
Gets the number of columns for this grid.
Returns:
The number of columns
getFrame
public int getFrame(
    int col,
    int row
)
Gets the current frame (image block index) of the given grid block. To understand image frames, see the documentation for Sprite.
Parameters:
colThe column number of the block
rowThe row number of the block
Returns:
The current frame
See Also:
getHeight
public float getHeight()
Gets the assigned height for this grid.
Returns:
The height of the grid in pixels
getRows
public int getRows()
Gets the number of rows for this grid.
Returns:
The number of rows
getWidth
public float getWidth()
Gets the assigned width for this grid.
Returns:
The width of the grid in pixels
render
public void render(
    RenderingContext context,
    int flags
)
Renders the visual content.
setAlpha
public void setAlpha(
    int col,
    int row,
    float alpha
)
Sets the transparency value of the given grid block.
Parameters:
colThe column number of the block
rowThe row number of the block
alphaThe new transparency (alpha) value
setFrame
public void setFrame(
    int col,
    int row,
    int frame
)
Sets the current frame of the given grid block. To understand image frames, see the documentation for Sprite.
Parameters:
colThe column number of the block
rowThe row number of the block
frameThe new frame number
See Also:
setVisibleRegion
public void setVisibleRegion(
    float startX,
    float startY,
    float endX,
    float endY
)
Sets the visible area within the grid block. The renderer will not render anything that lies outside the rectangular are specified. Use this method to achieve better performance. Note that there is no guarantee that the contents are clipped by the given area.
Parameters:
startXThe x coordinate of the region top-left corner
startYThe y coordinate of the region top-left corner
endXThe x coordinate of the region bottom-right corner
endYThe y coordinate of the region bottom-right corner