PDA

View Full Version : Java MIDP 1.0 S40 -- Sprites



marmotzel
25-11-2003, 03:32 PM
Hi,

I'm not sure if this is the right place to ask ... but ... here it goes :

I'm having a little problem trying to create my sprites from a big image containing all the artwork.

This is the code :

imageFrames = new Image[nFrames];
for ( nFrame = 0 ; nFrame < nFrames ; nFrame++ ) {
imageFrames[nFrame] = Image.createImage(CScreen.spriteW, CScreen.spriteH * sH);
gFrame = imageFrames[nFrame].getGraphics();
gFrame.drawImage(CScreen.imageArtwork, -(sX + nFrame*CScreen.spriteW), -sY, Graphics.TOP | Graphics.LEFT);
}

I think it's self explaining, but ... :)
nFrame = current frame number (a sprite may have multiple frames located in the artwork file on same row and consecutive cols)
nFrames = number of frames
spriteW, spriteH = size of sprite
sX, sY = location of (top, left) corner of the first frame within the artwork file
sH = hight of sprite in "sprite" dimensions (eg. a sprite may take have then one row)

Everything works fine, as long as sY = 0 (eg. it loads all the sprites (w/ or w/o multiple frames) from the top row) but when I try to load a sprite from the following rows I get garbage (sprite not loaded completly).

The technique i'm using is to create an empty image and copy the source image over the new image translated left and up. The translation works perfectly on X axis but not on the Y :(.

Strange thing : I added a piece of code to draw a black filled rectangle on the new image, and it worked, so the image is created with the correct size. However, the next line of code (the copy from source to dest) will copy only a small part of the image above the black rectangle as if it would be limited by something (and it's not !!)

my image (after creation) :
+ --------------------- +
| |
| |
| |
| |
| |
+ --------------------- +

my image (after black filled rectangle) :
o = black
+ --------------------- +
| ooooooooooooooooooo |
| ooooooooooooooooooo |
| ooooooooooooooooooo |
| ooooooooooooooooooo |
| ooooooooooooooooooo |
+ --------------------- +

my image (after image copy) :
o = black
. = image
+ --------------------- +
| .............................. |
| .............................. |
| .............................. |
| ooooooooooooooooooo |
| ooooooooooooooooooo |
+ --------------------- +

Now, the hight of the source image is a lot bigger then the hight of the destination image and it shouldn't stop drawing on the bottom part. The original location is good (eg, the image starts ok), but it's too small -- on Y axis (as if it's forced by something to stop drawing ...)

So please ... help !!! :)

Andrei Gavrila.