|
![]() |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.siemens.mp.misc.NativeMem
com.siemens.mp.game.GraphicObject
com.siemens.mp.game.Sprite
The Sprite class implements drawable sprite objects.
Sprites are figures or elements on the screen that have the
capability of moving independently of one another.
A sprite consists of one or more bitmaps - frames. When
a sprite has several frames, only one frame is visible on the display. The user
can change the visible frame at runtime by setFrame
method call, to implement some sort of animation.
When a sprite is created, the user provides a bitmap mask to select,
which regions of sprite will be drawn and which ones will be transparent.
Also, a collision rectangle may be set for each sprite by
setCollisionRectangle
method call. This rectangle may be used to check collision with
specific point or other sprite.
Because the Sprite class is a subclass of GraphicObject
,
it has no direct drawing capability available for the user. Instead,
when included into a GraphicObjectManager
collection, a sprite will be drawn in proper order on a
GraphicObjectManager.paint
method call.
GraphicObject
,
GraphicObjectManager
Constructor Summary | |
Sprite(byte[] pixels,
int pixel_offset,
int width,
int height,
byte[] mask,
int mask_offset,
int numFrames)
Creates a sprite directly from bytearrays. |
|
Sprite(ExtendedImage pixels,
ExtendedImage mask,
int numFrames)
Creates a sprite from previously created extended images. |
|
Sprite(Image pixels,
Image mask,
int numFrames)
Creates a sprite from previously created images. |
Method Summary | |
int |
getFrame()
Returns currently visible frame number. |
int |
getXPosition()
Returns the current x coordinate of the top-left corner of the sprite. |
int |
getYPosition()
Returns the current y coordinate of the top-left corner of the sprite. |
boolean |
isCollidingWith(Sprite other)
Checks if the sprite collides with another one. |
boolean |
isCollidingWithPos(int xpos,
int ypos)
Checks if the sprite collides with a specific point. |
void |
setCollisionRectangle(int x,
int y,
int width,
int height)
Sets the collision rectangle. |
void |
setFrame(int framenumber)
Sets the frame, which will become visible when the sprite is drawn. |
void |
setPosition(int x,
int y)
Sets the coordinates of the top-left corner of the sprite. |
Methods inherited from class com.siemens.mp.game.GraphicObject |
getVisible, setVisible |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Sprite(Image pixels, Image mask, int numFrames) throws IllegalArgumentException
Image
parameters
must be a multiple of 8. For more complete information on
sprite creation, see the Sprite(byte[], int, int, int, byte[], int, int)
constructor description.
Frames must be placed below each other, not side by side!
pixels
- a standard Image
with the image information; the width must be a multiple of 8mask
- a standard Image
with the mask information; the width must be a multiple of 8numFrames
- the number of frames the sprite has; the minimum is 1
IllegalArgumentException
- if the width of any image is not a multiple of 8,
Image
with transparent color is used,
public Sprite(ExtendedImage pixels, ExtendedImage mask, int numFrames) throws IllegalArgumentException
ExtendedImage
parameters
must be a multiple of 8. For more complete information on
sprite creation, see the Sprite(byte[], int, int, int, byte[], int, int)
constructor description.
Frames must be placed below each other, not side by side!
pixels
- an ExtendedImage
with the image information; the width must be a multiple of 8mask
- a ExtendedImage
with the mask information; the width must be a multiple of 8numFrames
- the number of frames the sprite has; the minimum is 1
IllegalArgumentException
- if the width of any image is not a multiple of 8,
ExtendedImage
with transparent color is used,
public Sprite(byte[] pixels, int pixel_offset, int width, int height, byte[] mask, int mask_offset, int numFrames) throws IllegalArgumentException
Both pixels and mask bytearrays contain one-bit-per-pixel (1 bpp) information. The pixels array contains bitmaps for all frames, one after another. Each bit value means: 1 - black pixel, 0 - white pixel. The mask array contains masks for all frames, one after another. Each bit value means: 1 - drawable pixel, 0 - transparent pixel. Bits in both arrays are placed line by line, frame by frame. Total number of bits in either pixels or mask array is
width*height*numFramesSo, the size of each array currently is restricted to
(width*height*numFrames)/8and the sprite width must be a multiple of 8.
pixels
- a bytearray with the image information (1 bpp), its size must be (width*height*numFrames)/8pixel_offset
- reserved, must be 0width
- the sprite width, must be a multiple of 8height
- the sprite height, must be a multiple of 8mask
- a bytearray with the mask information (1 bpp), its size must be (width*height*numFrames)/8mask_offset
- reserved, must be 0numFrames
- the number of frames the sprite has, the minimum is 1
IllegalArgumentException
- if the width is not a multiple of 8 or
GraphicObjectManager.createTextureBits
Method Detail |
public void setPosition(int x, int y)
GraphicObjectManager
drawing area coordinates.
x
- the x coordinate of the top-left corner of the spritey
- the y coordinate of the top-left corner of the spritegetXPosition
,
getYPosition
,
GraphicObjectManager.paint
public int getXPosition()
GraphicObjectManager
drawing area coordinates.
getYPosition
,
setPosition
,
GraphicObjectManager.paint
public int getYPosition()
GraphicObjectManager
drawing area coordinates.
getXPosition
,
setPosition
,
GraphicObjectManager.paint
public void setCollisionRectangle(int x, int y, int width, int height)
isCollidingWithPos
method call or to check collision with another sprite in
isCollidingWith
method call. The x and y values are relative to the sprite's own coordinates
(x=0 and y=0 is the sprite's top-left corner). Negative values
may be used for x and y parameters to set a collision rectangle
larger than the sprite itself.
x
- the x coordinate of the top-left corner of the sprite collision rectangley
- the y coordinate of the top-left corner of the sprite collision rectanglewidth
- the width of the sprite collision rectangleheight
- the height of the sprite collision rectangleisCollidingWith
,
isCollidingWithPos
public boolean isCollidingWith(Sprite other)
other
- a sprite to check collision with
setCollisionRectangle
,
isCollidingWithPos
,
GraphicObjectManager.paint
public boolean isCollidingWithPos(int xpos, int ypos)
GraphicObjectManager
drawing area coordinates.
xpos
- the x coordinate of the pointypos
- the y coordinate of the point
setCollisionRectangle
,
isCollidingWith
,
GraphicObjectManager.paint
public void setFrame(int framenumber)
framenumber
- the number of the frame (from zero to frameCount-1)getFrame
,
Sprite constructor
,
GraphicObjectManager.paint
public int getFrame()
setFrame
,
Sprite constructor
,
GraphicObjectManager.paint
|
![]() |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Generated on 2003-10-17 | For further information and updates, please visit Siemens mobile Developer Portal |