views:

726

answers:

3

Are there any libraries for J2ME to manage bitmap sprites for games?

+1  A: 

Hi,

There is not much to manage. You can load a png image with transparency info with Image.createImage("/sprite.png");

this image can be blitted anywhere on the screen.

You could create a simple sprite class, which has the image, an x and y position, and use this.

For simple collision detection you could just compare the bounding rectangles of 2 sprites.

R

Toad
+1  A: 

There's actually a game API in J2ME's MIDP 2.0 standard which has a bunch of game-centric classes, including a Sprite class. Check out this Tutorial for a good overview to using the J2ME Game API.

http://today.java.net/pub/a/today/2005/07/07/j2me3.html

Fostah
Is it very memory intensive to add 50 sprites per layer with 5 layers? Is there any lighter option like maintaining an array of images and drawing them myself?
Kevin Boyd
There isn't much to Layer, just bounds (4 ints) and visibility (1 boolean). On the Sprite front, it might be a bit of overkill if it's one frame per sprite, but not if you have any sequence of animation. I would probably isolate my resource and drawing logic and implement using the provided Sprite class. Then if its performance was not up to snuff it wouldn't be a huge effort to write your own Sprite engine and replace it in your game.
Fostah
Another note, as long as it isn't 50 unique image pieces, the Sprite class takes an Image instance as a constructor parameter. So, you would have only one copy of each sprite image loaded for the set of sprites it represents.
Fostah
+1  A: 

Try using a TiledLayer, it gives you the option to manage and array of images in a more elegant way. Also it is less memory intensive. You just load one tiled image and the TiledLayer will do the job for you

Ram