move a image using drawRegion in j2me

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

move a image using drawRegion in j2me

Postby itskrishnaraj » Thu Aug 07, 2008 2:28 pm

move a image (row of image) using j2me drawregion...jus give me any sample code to understand what is happening wen using drawRegion
itskrishnaraj
 
Posts: 39
Joined: Thu Aug 07, 2008 1:28 pm

Re: move a image using drawRegion in j2me

Postby DevelopmentTeam » Thu Aug 07, 2008 2:59 pm

This is really helpful , if you have any doubt post here...

From JSR 118 document
~~~~~~~~~~~~~~~~~~~~

drawRegion

public void drawRegion(Image src,
int x_src,
int y_src,
int width,
int height,
int transform,
int x_dest,
int y_dest,
int anchor)

Copies a region of the specified source image to a location within the destination, possibly transforming (rotating and reflecting) the image data using the chosen transform function.

The destination, if it is an image, must not be the same image as the source image. If it is, an exception is thrown. This restriction is present in order to avoid ill-defined behaviors that might occur if overlapped, transformed copies were permitted.

The transform function used must be one of the following, as defined in the Sprite class:
Sprite.TRANS_NONE - causes the specified image region to be copied unchanged
Sprite.TRANS_ROT90 - causes the specified image region to be rotated clockwise by 90 degrees.
Sprite.TRANS_ROT180 - causes the specified image region to be rotated clockwise by 180 degrees.
Sprite.TRANS_ROT270 - causes the specified image region to be rotated clockwise by 270 degrees.
Sprite.TRANS_MIRROR - causes the specified image region to be reflected about its vertical center.
Sprite.TRANS_MIRROR_ROT90 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 90 degrees.
Sprite.TRANS_MIRROR_ROT180 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 180 degrees.
Sprite.TRANS_MIRROR_ROT270 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 270 degrees.

If the source region contains transparent pixels, the corresponding pixels in the destination region must be left untouched. If the source region contains partially transparent pixels, a compositing operation must be performed with the destination pixels, leaving all pixels of the destination region fully opaque.

The (x_src, y_src) coordinates are relative to the upper left corner of the source image. The x_src, y_src, width, and height parameters specify a rectangular region of the source image. It is illegal for this region to extend beyond the bounds of the source image. This requires that:


x_src >= 0
y_src >= 0
x_src + width <= source width
y_src + height <= source height

The (x_dest, y_dest) coordinates are relative to the coordinate system of this Graphics object. It is legal for the destination area to extend beyond the bounds of the Graphics object. Pixels outside of the bounds of the Graphics object will not be drawn.

The transform is applied to the image data from the region of the source image, and the result is rendered with its anchor point positioned at location (x_dest, y_dest) in the destination.

Parameters:
src - the source image to copy from
x_src - the x coordinate of the upper left corner of the region within the source image to copy
y_src - the y coordinate of the upper left corner of the region within the source image to copy
width - the width of the region to copy
height - the height of the region to copy
transform - the desired transformation for the selected region being copied
x_dest - the x coordinate of the anchor point in the destination drawing area
y_dest - the y coordinate of the anchor point in the destination drawing area
anchor - the anchor point for positioning the region within the destination image
Throws:
IllegalArgumentException - if src is the same image as the destination of this Graphics object
NullPointerException - if src is null
IllegalArgumentException - if transform is invalid
IllegalArgumentException - if anchor is invalid
IllegalArgumentException - if the region to be copied exceeds the bounds of the source image
Since:
MIDP 2.0
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: move a image using drawRegion in j2me

Postby itskrishnaraj » Fri Aug 08, 2008 5:21 am

DevelopmentTeam wrote:This is really helpful , if you have any doubt post here...

From JSR 118 document
~~~~~~~~~~~~~~~~~~~~

drawRegion

public void drawRegion(Image src,
int x_src,
int y_src,
int width,
int height,
int transform,
int x_dest,
int y_dest,
int anchor)

Copies a region of the specified source image to a location within the destination, possibly transforming (rotating and reflecting) the image data using the chosen transform function.

The destination, if it is an image, must not be the same image as the source image. If it is, an exception is thrown. This restriction is present in order to avoid ill-defined behaviors that might occur if overlapped, transformed copies were permitted.

The transform function used must be one of the following, as defined in the Sprite class:
Sprite.TRANS_NONE - causes the specified image region to be copied unchanged
Sprite.TRANS_ROT90 - causes the specified image region to be rotated clockwise by 90 degrees.
Sprite.TRANS_ROT180 - causes the specified image region to be rotated clockwise by 180 degrees.
Sprite.TRANS_ROT270 - causes the specified image region to be rotated clockwise by 270 degrees.
Sprite.TRANS_MIRROR - causes the specified image region to be reflected about its vertical center.
Sprite.TRANS_MIRROR_ROT90 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 90 degrees.
Sprite.TRANS_MIRROR_ROT180 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 180 degrees.
Sprite.TRANS_MIRROR_ROT270 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 270 degrees.

If the source region contains transparent pixels, the corresponding pixels in the destination region must be left untouched. If the source region contains partially transparent pixels, a compositing operation must be performed with the destination pixels, leaving all pixels of the destination region fully opaque.

The (x_src, y_src) coordinates are relative to the upper left corner of the source image. The x_src, y_src, width, and height parameters specify a rectangular region of the source image. It is illegal for this region to extend beyond the bounds of the source image. This requires that:


x_src >= 0
y_src >= 0
x_src + width <= source width
y_src + height <= source height

The (x_dest, y_dest) coordinates are relative to the coordinate system of this Graphics object. It is legal for the destination area to extend beyond the bounds of the Graphics object. Pixels outside of the bounds of the Graphics object will not be drawn.

The transform is applied to the image data from the region of the source image, and the result is rendered with its anchor point positioned at location (x_dest, y_dest) in the destination.

Parameters:
src - the source image to copy from
x_src - the x coordinate of the upper left corner of the region within the source image to copy
y_src - the y coordinate of the upper left corner of the region within the source image to copy
width - the width of the region to copy
height - the height of the region to copy
transform - the desired transformation for the selected region being copied
x_dest - the x coordinate of the anchor point in the destination drawing area
y_dest - the y coordinate of the anchor point in the destination drawing area
anchor - the anchor point for positioning the region within the destination image
Throws:
IllegalArgumentException - if src is the same image as the destination of this Graphics object
NullPointerException - if src is null
IllegalArgumentException - if transform is invalid
IllegalArgumentException - if anchor is invalid
IllegalArgumentException - if the region to be copied exceeds the bounds of the source image
Since:
MIDP 2.0







now i am able to move a image using drawRegion ..moving image in a diagonal way...now i want to move it downward ...i am using the MIRROR_Transfom for that ..wat abt the Des_x and Des_y value.....?
itskrishnaraj
 
Posts: 39
Joined: Thu Aug 07, 2008 1:28 pm

Re: move a image using drawRegion in j2me

Postby DevelopmentTeam » Fri Aug 08, 2008 5:34 am

itskrishnaraj wrote:now i am able to move a image using drawRegion ..moving image in a diagonal way...now i want to move it downward ...i am using the MIRROR_Transfom for that ..wat abt the Des_x and Des_y value.....?


des_x and des_y are the destination points on the screen where the image is drawn.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India


Return to J2ME Games

Who is online

Users browsing this forum: No registered users and 2 guests

cron