Java Doc for Sprite.java in  » 6.0-JDK-Modules » j2me » javax » microedition » lcdui » game » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » javax.microedition.lcdui.game 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javax.microedition.lcdui.game.Layer
      javax.microedition.lcdui.game.Sprite

Sprite
public class Sprite extends Layer (Code)
A Sprite is a basic visual element that can be rendered with one of several frames stored in an Image; different frames can be shown to animate the Sprite. Several transforms such as flipping and rotation can also be applied to a Sprite to further vary its appearance. As with all Layer subclasses, a Sprite's location can be changed and it can also be made visible or invisible.

Sprite Frames

The raw frames used to render a Sprite are provided in a single Image object, which may be mutable or immutable. If more than one frame is used, the Image is broken up into a series of equally-sized frames of a specified width and height. As shown in the figure below, the same set of frames may be stored in several different arrangements depending on what is the most convenient for the game developer.
Sprite Frames

Each frame is assigned a unique index number. The frame located in the upper-left corner of the Image is assigned an index of 0. The remaining frames are then numbered consecutively in row-major order (indices are assigned across the first row, then the second row, and so on). The method Sprite.getRawFrameCount() returns the total number of raw frames.

Frame Sequence

A Sprite's frame sequence defines an ordered list of frames to be displayed. The default frame sequence mirrors the list of available frames, so there is a direct mapping between the sequence index and the corresponding frame index. This also means that the length of the default frame sequence is equal to the number of raw frames. For example, if a Sprite has 4 frames, its default frame sequence is {0, 1, 2, 3}.
Default Frame Sequence

The developer must manually switch the current frame in the frame sequence. This may be accomplished by calling Sprite.setFrame , Sprite.prevFrame() , or Sprite.nextFrame() . Note that these methods always operate on the sequence index, they do not operate on frame indices; however, if the default frame sequence is used, then the sequence indices and the frame indices are interchangeable.

If desired, an arbitrary frame sequence may be defined for a Sprite. The frame sequence must contain at least one element, and each element must reference a valid frame index. By defining a new frame sequence, the developer can conveniently display the Sprite's frames in any order desired; frames may be repeated, omitted, shown in reverse order, etc.

For example, the diagram below shows how a special frame sequence might be used to animate a mosquito. The frame sequence is designed so that the mosquito flaps its wings three times and then pauses for a moment before the cycle is repeated.

Special Frame Sequence
By calling Sprite.nextFrame each time the display is updated, the resulting animation would like this:

Reference Pixel

Being a subclass of Layer, Sprite inherits various methods for setting and retrieving its location such as Sprite.setPosition setPosition(x,y) , Sprite.getX getX() , and Sprite.getY getY() . These methods all define position in terms of the upper-left corner of the Sprite's visual bounds; however, in some cases, it is more convenient to define the Sprite's position in terms of an arbitrary pixel within its frame, especially if transforms are applied to the Sprite.

Therefore, Sprite includes the concept of a reference pixel. The reference pixel is defined by specifying its location in the Sprite's untransformed frame using Sprite.defineReferencePixel defineReferencePixel(x,y) . By default, the reference pixel is defined to be the pixel at (0,0) in the frame. If desired, the reference pixel may be defined outside of the frame's bounds.

In this example, the reference pixel is defined to be the pixel that the monkey appears to be hanging from:

Defining The Reference Pixel

Sprite.getRefPixelX getRefPixelX() and Sprite.getRefPixelY getRefPixelY() can be used to query the location of the reference pixel in the painter's coordinate system. The developer can also use Sprite.setRefPixelPosition setRefPixelPosition(x,y) to position the Sprite so that reference pixel appears at a specific location in the painter's coordinate system. These methods automatically account for any transforms applied to the Sprite.

In this example, the reference pixel's position is set to a point at the end of a tree branch; the Sprite's location changes so that the reference pixel appears at this point and the monkey appears to be hanging from the branch:

Setting The Reference Pixel Position

Sprite Transforms

Various transforms can be applied to a Sprite. The available transforms include rotations in multiples of 90 degrees, and mirrored (about the vertical axis) versions of each of the rotations. A Sprite's transform is set by calling Sprite.setTransform setTransform(transform) .

Transforms

When a transform is applied, the Sprite is automatically repositioned such that the reference pixel appears stationary in the painter's coordinate system. Thus, the reference pixel effectively becomes the center of the transform operation. Since the reference pixel does not move, the values returned by Sprite.getRefPixelX() and Sprite.getRefPixelY() remain the same; however, the values returned by Sprite.getX getX() and Sprite.getY getY() may change to reflect the movement of the Sprite's upper-left corner.

Referring to the monkey example once again, the position of the reference pixel remains at (48, 22) when a 90 degree rotation is applied, thereby making it appear as if the monkey is swinging from the branch:

Transform Center

Sprite Drawing

Sprites can be drawn at any time using the Sprite.paint(Graphics) method. The Sprite will be drawn on the Graphics object according to the current state information maintained by the Sprite (i.e. position, frame, visibility). Erasing the Sprite is always the responsibility of code outside the Sprite class.

Sprites can be implemented using whatever techniques a manufacturers wishes to use (e.g hardware acceleration may be used for all Sprites, for certain sizes of Sprites, or not at all).

For some platforms, certain Sprite sizes may be more efficient than others; manufacturers may choose to provide developers with information about device-specific characteristics such as these.



Field Summary
final public static  intTRANS_MIRROR
     Causes the Sprite to appear reflected about its vertical center.
final public static  intTRANS_MIRROR_ROT180
     Causes the Sprite to appear reflected about its vertical center and then rotated clockwise by 180 degrees.
final public static  intTRANS_MIRROR_ROT270
     Causes the Sprite to appear reflected about its vertical center and then rotated clockwise by 270 degrees.
final public static  intTRANS_MIRROR_ROT90
     Causes the Sprite to appear reflected about its vertical center and then rotated clockwise by 90 degrees.
final public static  intTRANS_NONE
     No transform is applied to the Sprite.
final public static  intTRANS_ROT180
     Causes the Sprite to appear rotated clockwise by 180 degrees.
final public static  intTRANS_ROT270
     Causes the Sprite to appear rotated clockwise by 270 degrees.
final public static  intTRANS_ROT90
     Causes the Sprite to appear rotated clockwise by 90 degrees.
 intcollisionRectHeight
     Height of the bounding rectangle for collision detection.
 intcollisionRectWidth
     Width of the bounding rectangle for collision detection.
 intcollisionRectX
     Horizontal offset of the top left of the collision rectangle from the top left of the sprite.
 intcollisionRectY
     Vertical offset of the top left of the collision rectangle from the top left of the sprite.
 intdRefX
     Horizontal offset of the reference point from the top left of the sprite.
 intdRefY
     Vertical offset of the reference point from the top left of the sprite.
 int[]frameCoordsX
    
 int[]frameCoordsY
    
 int[]frameSequence
    
 intnumberFrames
    
 ImagesourceImage
    
 intsrcFrameHeight
    
 intsrcFrameWidth
    
 intt_collisionRectHeight
     Height of the bounding rectangle for collision detection, with the current transformation in effect.
 intt_collisionRectWidth
     Width of the bounding rectangle for collision detection, with the current transformation in effect.
 intt_collisionRectX
     Horizontal offset of the top left of the collision rectangle from the top left of the sprite.
 intt_collisionRectY
     Vertical offset of the top left of the collision rectangle from the top left of the sprite.
 intt_currentTransformation
     The current transformation in effect.

Constructor Summary
public  Sprite(Image image)
     Creates a new non-animated Sprite using the provided Image.
public  Sprite(Image image, int frameWidth, int frameHeight)
     Creates a new animated Sprite using frames contained in the provided Image.
public  Sprite(Sprite s)
     Creates a new Sprite from another Sprite.

Method Summary
final public  booleancollidesWith(Sprite s, boolean pixelLevel)
     Checks for a collision between this Sprite and the specified Sprite.

If pixel-level detection is used, a collision is detected only if opaque pixels collide.

final public  booleancollidesWith(TiledLayer t, boolean pixelLevel)
     Checks for a collision between this Sprite and the specified TiledLayer.
final public  booleancollidesWith(Image image, int inp_x, int inp_y, boolean pixelLevel)
     Checks for a collision between this Sprite and the specified Image with its upper left corner at the specified location.
public  voiddefineCollisionRectangle(int inp_x, int inp_y, int width, int height)
     Defines the Sprite's bounding rectangle that is used for collision detection purposes.
public  voiddefineReferencePixel(int inp_x, int inp_y)
     Defines the reference pixel for this Sprite.
final public  intgetFrame()
     Gets the current index in the frame sequence.
public  intgetFrameSequenceLength()
     Gets the number of elements in the frame sequence.
public  intgetRawFrameCount()
     Gets the number of raw frames for this Sprite.
public  intgetRefPixelX()
     Gets the horizontal position of this Sprite's reference pixel in the painter's coordinate system.
public  intgetRefPixelY()
     Gets the vertical position of this Sprite's reference pixel in the painter's coordinate system.
 intgetTransformedPtX(int inp_x, int inp_y, int transform)
     Given the x and y offsets off a pixel from the top left corner, in an untransformed sprite, calculates the x coordinate of the pixel when the same sprite is transformed, with the coordinates of the top-left pixel of the transformed sprite as (0,0).
 intgetTransformedPtY(int inp_x, int inp_y, int transform)
     Given the x and y offsets off a pixel from the top left corner, in an untransformed sprite, calculates the y coordinate of the pixel when the same sprite is transformed, with the coordinates of the top-left pixel of the transformed sprite as (0,0).
public  voidnextFrame()
     Selects the next frame in the frame sequence.
final public  voidpaint(Graphics g)
     Draws the Sprite.
public  voidprevFrame()
     Selects the previous frame in the frame sequence.
public  voidsetFrame(int inp_sequenceIndex)
     Selects the current frame in the frame sequence.
public  voidsetFrameSequence(int sequence)
     Set the frame sequence for this Sprite.
public  voidsetImage(Image img, int frameWidth, int frameHeight)
     Changes the Image containing the Sprite's frames.
public  voidsetRefPixelPosition(int inp_x, int inp_y)
     Sets this Sprite's position such that its reference pixel is located at (x,y) in the painter's coordinate system.
public  voidsetTransform(int transform)
     Sets the transform for this Sprite.

Field Detail
TRANS_MIRROR
final public static int TRANS_MIRROR(Code)
Causes the Sprite to appear reflected about its vertical center. This constant has a value of 2.



TRANS_MIRROR_ROT180
final public static int TRANS_MIRROR_ROT180(Code)
Causes the Sprite to appear reflected about its vertical center and then rotated clockwise by 180 degrees. This constant has a value of 1.



TRANS_MIRROR_ROT270
final public static int TRANS_MIRROR_ROT270(Code)
Causes the Sprite to appear reflected about its vertical center and then rotated clockwise by 270 degrees. This constant has a value of 4.



TRANS_MIRROR_ROT90
final public static int TRANS_MIRROR_ROT90(Code)
Causes the Sprite to appear reflected about its vertical center and then rotated clockwise by 90 degrees. This constant has a value of 7.



TRANS_NONE
final public static int TRANS_NONE(Code)
No transform is applied to the Sprite. This constant has a value of 0.



TRANS_ROT180
final public static int TRANS_ROT180(Code)
Causes the Sprite to appear rotated clockwise by 180 degrees. This constant has a value of 3.



TRANS_ROT270
final public static int TRANS_ROT270(Code)
Causes the Sprite to appear rotated clockwise by 270 degrees. This constant has a value of 6.



TRANS_ROT90
final public static int TRANS_ROT90(Code)
Causes the Sprite to appear rotated clockwise by 90 degrees. This constant has a value of 5.



collisionRectHeight
int collisionRectHeight(Code)
Height of the bounding rectangle for collision detection.



collisionRectWidth
int collisionRectWidth(Code)
Width of the bounding rectangle for collision detection.



collisionRectX
int collisionRectX(Code)
Horizontal offset of the top left of the collision rectangle from the top left of the sprite.



collisionRectY
int collisionRectY(Code)
Vertical offset of the top left of the collision rectangle from the top left of the sprite.



dRefX
int dRefX(Code)
Horizontal offset of the reference point from the top left of the sprite.



dRefY
int dRefY(Code)
Vertical offset of the reference point from the top left of the sprite.



frameCoordsX
int[] frameCoordsX(Code)
list of X coordinates of individual frames



frameCoordsY
int[] frameCoordsY(Code)
list of Y coordinates of individual frames



frameSequence
int[] frameSequence(Code)
The sequence in which to display the Sprite frames



numberFrames
int numberFrames(Code)
The number of frames



sourceImage
Image sourceImage(Code)
Source image



srcFrameHeight
int srcFrameHeight(Code)
Height of each frame in the source image



srcFrameWidth
int srcFrameWidth(Code)
Width of each frame in the source image



t_collisionRectHeight
int t_collisionRectHeight(Code)
Height of the bounding rectangle for collision detection, with the current transformation in effect.



t_collisionRectWidth
int t_collisionRectWidth(Code)
Width of the bounding rectangle for collision detection, with the current transformation in effect.



t_collisionRectX
int t_collisionRectX(Code)
Horizontal offset of the top left of the collision rectangle from the top left of the sprite.



t_collisionRectY
int t_collisionRectY(Code)
Vertical offset of the top left of the collision rectangle from the top left of the sprite.



t_currentTransformation
int t_currentTransformation(Code)
The current transformation in effect.




Constructor Detail
Sprite
public Sprite(Image image)(Code)
Creates a new non-animated Sprite using the provided Image. This constructor is functionally equivalent to calling new Sprite(image, image.getWidth(), image.getHeight())

By default, the Sprite is visible and its upper-left corner is positioned at (0,0) in the painter's coordinate system.

Parameters:
  image - the Image to use as the single framefor the Sprite
throws:
  NullPointerException - if img is null




Sprite
public Sprite(Image image, int frameWidth, int frameHeight)(Code)
Creates a new animated Sprite using frames contained in the provided Image. The frames must be equally sized, with the dimensions specified by frameWidth and frameHeight. 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, and the height of the source image must be an integer multiple of the frame height. The values returned by Layer.getWidth and Layer.getHeight will reflect the frame width and frame height subject to the Sprite's current transform.

Sprites have a default frame sequence corresponding to the raw frame numbers, starting with frame 0. The frame sequence may be modified with Sprite.setFrameSequence(int[]) .

By default, the Sprite is visible and its upper-left corner is positioned at (0,0) in the painter's coordinate system.


Parameters:
  image - the Image to use for Sprite
Parameters:
  frameWidth - the width, in pixels, of theindividual raw frames
Parameters:
  frameHeight - the height, in pixels, of theindividual raw frames
throws:
  NullPointerException - if img is null
throws:
  IllegalArgumentException - if frameHeight orframeWidth is less than 1
throws:
  IllegalArgumentException - if the imagewidth is not an integer multiple of the frameWidth
throws:
  IllegalArgumentException - if the imageheight is not an integer multiple of the frameHeight




Sprite
public Sprite(Sprite s)(Code)
Creates a new Sprite from another Sprite.

All instance attributes (raw frames, position, frame sequence, current frame, reference point, collision rectangle, transform, and visibility) of the source Sprite are duplicated in the new Sprite.
Parameters:
  s - the Sprite to create a copy of
throws:
  NullPointerException - if s is null





Method Detail
collidesWith
final public boolean collidesWith(Sprite s, boolean pixelLevel)(Code)
Checks for a collision between this Sprite and the specified Sprite.

If pixel-level detection is used, a collision is detected only if opaque pixels collide. That is, an opaque pixel in the first Sprite would have to collide with an opaque pixel in the second Sprite for a collision to be detected. Only those pixels within the Sprites' respective collision rectangles are checked.

If pixel-level detection is not used, this method simply checks if the Sprites' collision rectangles intersect.

Any transforms applied to the Sprites are automatically accounted for.

Both Sprites must be visible in order for a collision to be detected.


Parameters:
  s - the Sprite to test for collision with
Parameters:
  pixelLevel - true to test for collision on apixel-by-pixel basis, false to test using simplebounds checking. true if the two Sprites have collided, otherwisefalse
throws:
  NullPointerException - if Sprite s is null




collidesWith
final public boolean collidesWith(TiledLayer t, boolean pixelLevel)(Code)
Checks for a collision between this Sprite and the specified TiledLayer. If pixel-level detection is used, a collision is detected only if opaque pixels collide. That is, an opaque pixel in the Sprite would have to collide with an opaque pixel in TiledLayer for a collision to be detected. Only those pixels within the Sprite's collision rectangle are checked.

If pixel-level detection is not used, this method simply checks if the Sprite's collision rectangle intersects with a non-empty cell in the TiledLayer.

Any transform applied to the Sprite is automatically accounted for.

The Sprite and the TiledLayer must both be visible in order for a collision to be detected.


Parameters:
  t - the TiledLayer to test for collision with
Parameters:
  pixelLevel - true to test for collision on apixel-by-pixel basis, false to test using simple boundschecking against non-empty cells. true if this Sprite hascollided with the TiledLayer, otherwisefalse
throws:
  NullPointerException - if t is null




collidesWith
final public boolean collidesWith(Image image, int inp_x, int inp_y, boolean pixelLevel)(Code)
Checks for a collision between this Sprite and the specified Image with its upper left corner at the specified location. If pixel-level detection is used, a collision is detected only if opaque pixels collide. That is, an opaque pixel in the Sprite would have to collide with an opaque pixel in Image for a collision to be detected. Only those pixels within the Sprite's collision rectangle are checked.

If pixel-level detection is not used, this method simply checks if the Sprite's collision rectangle intersects with the Image's bounds.

Any transform applied to the Sprite is automatically accounted for.

The Sprite must be visible in order for a collision to be detected.


Parameters:
  image - the Image to test for collision
Parameters:
  inp_x - the horizontal location of the Image'supper left corner
Parameters:
  inp_y - the vertical location of the Image'supper left corner
Parameters:
  pixelLevel - true to test for collision on apixel-by-pixel basis, false to test using simplebounds checking true if this Sprite hascollided with the Image, otherwisefalse
throws:
  NullPointerException - if image isnull




defineCollisionRectangle
public void defineCollisionRectangle(int inp_x, int inp_y, int width, int height)(Code)
Defines the Sprite's bounding rectangle that is used for collision detection purposes. This rectangle is specified relative to the un-transformed Sprite's upper-left corner and defines the area that is checked for collision detection. For pixel-level detection, only those pixels within the collision rectangle are checked. By default, a Sprite's collision rectangle is located at 0,0 as has the same dimensions as the Sprite. The collision rectangle may be specified to be larger or smaller than the default rectangle; if made larger, the pixels outside the bounds of the Sprite are considered to be transparent for pixel-level collision detection.
Parameters:
  inp_x - the horizontal location of the collision rectangle relative to the untransformed Sprite's left edge
Parameters:
  inp_y - the vertical location of the collision rectangle relative tothe untransformed Sprite's top edge
Parameters:
  width - the width of the collision rectangle
Parameters:
  height - the height of the collision rectangle
throws:
  IllegalArgumentException - if the specifiedwidth or height isless than 0



defineReferencePixel
public void defineReferencePixel(int inp_x, int inp_y)(Code)
Defines the reference pixel for this Sprite. The pixel is defined by its location relative to the upper-left corner of the Sprite's un-transformed frame, and it may lay outside of the frame's bounds.

When a transformation is applied, the reference pixel is defined relative to the Sprite's initial upper-left corner before transformation. This corner may no longer appear as the upper-left corner in the painter's coordinate system under current transformation.

By default, a Sprite's reference pixel is located at (0,0); that is, the pixel in the upper-left corner of the raw frame.

Changing the reference pixel does not change the Sprite's physical position in the painter's coordinate system; that is, the values returned by Sprite.getX getX() and Sprite.getY getY() will not change as a result of defining the reference pixel. However, subsequent calls to methods that involve the reference pixel will be impacted by its new definition.
Parameters:
  inp_x - the horizontal location of the reference pixel, relativeto the left edge of the un-transformed frame
Parameters:
  inp_y - the vertical location of the reference pixel, relativeto the top edge of the un-transformed frame
See Also:   Sprite.setRefPixelPosition
See Also:   Sprite.getRefPixelX
See Also:   Sprite.getRefPixelY




getFrame
final public int getFrame()(Code)
Gets the current index in the frame sequence.

The index returned refers to the current entry in the frame sequence, not the index of the actual frame that is displayed. the current index in the frame sequence
See Also:   Sprite.setFrameSequence(int[])
See Also:   Sprite.setFrame




getFrameSequenceLength
public int getFrameSequenceLength()(Code)
Gets the number of elements in the frame sequence. The value returned reflects the length of the Sprite's frame sequence; it does not reflect the number of raw frames. However, these two values will be the same if the default frame sequence is used. the number of elements in this Sprite's frame sequence
See Also:   Sprite.getRawFrameCount



getRawFrameCount
public int getRawFrameCount()(Code)
Gets the number of raw frames for this Sprite. The value returned reflects the number of frames; it does not reflect the length of the Sprite's frame sequence. However, these two values will be the same if the default frame sequence is used. the number of raw frames for this Sprite
See Also:   Sprite.getFrameSequenceLength



getRefPixelX
public int getRefPixelX()(Code)
Gets the horizontal position of this Sprite's reference pixel in the painter's coordinate system. the horizontal location of the reference pixel
See Also:   Sprite.defineReferencePixel
See Also:   Sprite.setRefPixelPosition
See Also:   Sprite.getRefPixelY



getRefPixelY
public int getRefPixelY()(Code)
Gets the vertical position of this Sprite's reference pixel in the painter's coordinate system. the vertical location of the reference pixel
See Also:   Sprite.defineReferencePixel
See Also:   Sprite.setRefPixelPosition
See Also:   Sprite.getRefPixelX



getTransformedPtX
int getTransformedPtX(int inp_x, int inp_y, int transform)(Code)
Given the x and y offsets off a pixel from the top left corner, in an untransformed sprite, calculates the x coordinate of the pixel when the same sprite is transformed, with the coordinates of the top-left pixel of the transformed sprite as (0,0).
Parameters:
  inp_x - Horizontal offset within the untransformed sprite
Parameters:
  inp_y - Vertical offset within the untransformed sprite
Parameters:
  transform - transform for the sprite The x-offset, of the coordinates of the pixel,with the top-left corner as 0 when transformed.



getTransformedPtY
int getTransformedPtY(int inp_x, int inp_y, int transform)(Code)
Given the x and y offsets off a pixel from the top left corner, in an untransformed sprite, calculates the y coordinate of the pixel when the same sprite is transformed, with the coordinates of the top-left pixel of the transformed sprite as (0,0).
Parameters:
  inp_x - Horizontal offset within the untransformed sprite
Parameters:
  inp_y - Vertical offset within the untransformed sprite
Parameters:
  transform - transform for the sprite The y-offset, of the coordinates of the pixel,with the top-left corner as 0 when transformed.



nextFrame
public void nextFrame()(Code)
Selects the next frame in the frame sequence.

The frame sequence is considered to be circular, i.e. if Sprite.nextFrame is called when at the end of the sequence, this method will advance to the first entry in the sequence.
See Also:   Sprite.setFrameSequence(int[])
See Also:   Sprite.prevFrame




paint
final public void paint(Graphics g)(Code)
Draws the Sprite.

Draws current frame of Sprite using the provided Graphics object. The Sprite's upper left corner is rendered at the Sprite's current position relative to the origin of the Graphics object. The current position of the Sprite's upper-left corner can be retrieved by calling Sprite.getX() and Sprite.getY() .

Rendering is subject to the clip region of the Graphics object. The Sprite will be drawn only if it is visible.

If the Sprite's Image is mutable, the Sprite is rendered using the current contents of the Image.
Parameters:
  g - the graphics object to draw Sprite on
throws:
  NullPointerException - if g is null




prevFrame
public void prevFrame()(Code)
Selects the previous frame in the frame sequence.

The frame sequence is considered to be circular, i.e. if Sprite.prevFrame is called when at the start of the sequence, this method will advance to the last entry in the sequence.
See Also:   Sprite.setFrameSequence(int[])
See Also:   Sprite.nextFrame




setFrame
public void setFrame(int inp_sequenceIndex)(Code)
Selects the current frame in the frame sequence.

The current frame is rendered when Sprite.paint(Graphics) is called.

The index provided refers to the desired entry in the frame sequence, not the index of the actual frame itself.
Parameters:
  inp_sequenceIndex - the index of of the desired entry in the frame sequence
throws:
  IndexOutOfBoundsException - if frameIndex isless than0
throws:
  IndexOutOfBoundsException - if frameIndex isequal to or greater than the length of the current framesequence (or the number of raw frames for the default sequence)
See Also:   Sprite.setFrameSequence(int[])
See Also:   Sprite.getFrame




setFrameSequence
public void setFrameSequence(int sequence)(Code)
Set the frame sequence for this Sprite.

All Sprites have a default sequence that displays the Sprites frames in order. This method allows for the creation of an arbitrary sequence using the available frames. The current index in the frame sequence is reset to zero as a result of calling this method.

The contents of the sequence array are copied when this method is called; thus, any changes made to the array after this method returns have no effect on the Sprite's frame sequence.

Passing in null causes the Sprite to revert to the default frame sequence.


Parameters:
  sequence - an array of integers, where each integer representsa frame index
throws:
  ArrayIndexOutOfBoundsException - if seq is non-null and any memberof the array has a value less than 0 orgreater than or equal to thenumber of frames as reported by Sprite.getRawFrameCount()
throws:
  IllegalArgumentException - if the array has less than1 element
See Also:   Sprite.nextFrame
See Also:   Sprite.prevFrame
See Also:   Sprite.setFrame
See Also:   Sprite.getFrame




setImage
public void setImage(Image img, int frameWidth, int frameHeight)(Code)
Changes the Image containing the Sprite's frames.

Replaces the current raw frames of the Sprite with a new set of raw frames. See the constructor Sprite.Sprite(Image,int,int) for information on how the frames are created from the image. The values returned by Layer.getWidth and Layer.getHeight will reflect the new frame width and frame height subject to the Sprite's current transform.

Changing the image for the Sprite could change the number of raw frames. If the new frame set has as many or more raw frames than the previous frame set, then:

  • The current frame will be unchanged
  • If a custom frame sequence has been defined (using Sprite.setFrameSequence(int[]) ), it will remain unchanged. If no custom frame sequence is defined (i.e. the default frame sequence is in use), the default frame sequence will be updated to be the default frame sequence for the new frame set. In other words, the new default frame sequence will include all of the frames from the new raw frame set, as if this new image had been used in the constructor.

If the new frame set has fewer frames than the previous frame set, then:

  • The current frame will be reset to entry 0
  • Any custom frame sequence will be discarded and the frame sequence will revert to the default frame sequence for the new frame set.

The reference point location is unchanged as a result of calling this method, both in terms of its defined location within the Sprite and its position in the painter's coordinate system. However, if the frame size is changed and the Sprite has been transformed, the position of the Sprite's upper-left corner may change such that the reference point remains stationary.

If the Sprite's frame size is changed by this method, the collision rectangle is reset to its default value (i.e. it is set to the new bounds of the untransformed Sprite).


Parameters:
  img - the Image to use forSprite
Parameters:
  frameWidth - the width in pixels of the individual raw frames
Parameters:
  frameHeight - the height in pixels of the individual raw frames
throws:
  NullPointerException - if img is null
throws:
  IllegalArgumentException - if frameHeight or frameWidth is less than 1
throws:
  IllegalArgumentException - if the image width is not an integermultiple of the frameWidth
throws:
  IllegalArgumentException - if the image height is not an integer multiple of the frameHeight




setRefPixelPosition
public void setRefPixelPosition(int inp_x, int inp_y)(Code)
Sets this Sprite's position such that its reference pixel is located at (x,y) in the painter's coordinate system.
Parameters:
  inp_x - the horizontal location at which to place the reference pixel
Parameters:
  inp_y - the vertical location at which to place the reference pixel
See Also:   Sprite.defineReferencePixel
See Also:   Sprite.getRefPixelX
See Also:   Sprite.getRefPixelY



setTransform
public void setTransform(int transform)(Code)
Sets the transform for this Sprite. Transforms can be applied to a Sprite to change its rendered appearance. Transforms are applied to the original Sprite image; they are not cumulative, nor can they be combined. By default, a Sprite's transform is Sprite.TRANS_NONE .

Since some transforms involve rotations of 90 or 270 degrees, their use may result in the overall width and height of the Sprite being swapped. As a result, the values returned by Layer.getWidth and Layer.getHeight may change.

The collision rectangle is also modified by the transform so that it remains static relative to the pixel data of the Sprite. Similarly, the defined reference pixel is unchanged by this method, but its visual location within the Sprite may change as a result.

This method repositions the Sprite so that the location of the reference pixel in the painter's coordinate system does not change as a result of changing the transform. Thus, the reference pixel effectively becomes the centerpoint for the transform. Consequently, the values returned by Sprite.getRefPixelX and Sprite.getRefPixelY will be the same both before and after the transform is applied, but the values returned by Sprite.getX getX() and Sprite.getY getY() may change.


Parameters:
  transform - the desired transform for this Sprite
throws:
  IllegalArgumentException - if the requestedtransform is invalid
See Also:   Sprite.TRANS_NONE
See Also:   Sprite.TRANS_ROT90
See Also:   Sprite.TRANS_ROT180
See Also:   Sprite.TRANS_ROT270
See Also:   Sprite.TRANS_MIRROR
See Also:   Sprite.TRANS_MIRROR_ROT90
See Also:   Sprite.TRANS_MIRROR_ROT180
See Also:   Sprite.TRANS_MIRROR_ROT270




Fields inherited from javax.microedition.lcdui.game.Layer
int height(Code)(Java Doc)
boolean visible(Code)(Java Doc)
int width(Code)(Java Doc)
int x(Code)(Java Doc)
int y(Code)(Java Doc)

Methods inherited from javax.microedition.lcdui.game.Layer
final public int getHeight()(Code)(Java Doc)
final public int getWidth()(Code)(Java Doc)
final public int getX()(Code)(Java Doc)
final public int getY()(Code)(Java Doc)
final public boolean isVisible()(Code)(Java Doc)
public void move(int dx, int dy)(Code)(Java Doc)
abstract public void paint(Graphics g)(Code)(Java Doc)
void setHeightImpl(int height)(Code)(Java Doc)
public void setPosition(int x, int y)(Code)(Java Doc)
public void setVisible(boolean visible)(Code)(Java Doc)
void setWidthImpl(int width)(Code)(Java Doc)

Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.