1
votes

In J2ME, only a screen or a canvas can be displayed at a time. The screen can have multiple objects inside it (textfield, form, etc.) while a canvas can only hold a gamecanvas.

The question is: Is it possible to have multiple game canvases in one canvas? I'm trying to display two at the same time, one at the top and one at the bottom. I'd like to repaint the bottom canvas without repainting the top.

Thank you in advance! Any form of help will be appreciated! :)

2
I think, yes, you can do this. Look at this short tutorial that shows how to perform screen transitions in J2ME (during which, two canvases both momentarily appear at the same time). You should be able to use the same technique to display the two canvases together permanently. jappit.com/blog/2008/06/23/… - ban-geoengineering

2 Answers

2
votes

No, you can only display one Canvas or GameCanvas object at a time.

But: If you're asking about having 2 Canvas objects, because you need to update 2 parts of the screen independent of each other, you can do that by using 2 Image objects.

Simply get the Graphics object of each Image with Image.getGraphics(); Then you can draw onto each image. And finally draw both images on the canvas (or just one of them, if you only want to update one part of the screen).

Example using GameCanvas:

Image topImage = Image.createImage(width, height);
Image bottomImage = Image.createImage(width, height);
Graphics topG = topImage.getGraphics();
Graphics bottomG = bottomImage.getGraphics();
Graphics g = getGraphics(); // Get graphics of the GameCanvas

drawStuffOn-topG();
drawStuffOn-bottomG();

g.drawImage(topImage, 0, 0, g.TOP|g.LEFT);
g.drawImage(bottomImage, 0, halfScreenHeight, g.TOP|g.LEFT);

flushGraphics();
1
votes

No, you use just one canvas, but repaint only the bits that have changed using

Canvas.repaint(int x, int y, int w, int h);