p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

j2me thread: Re: Game Application


Message #1 by shenbo@m... on Thu, 5 Dec 2002 07:49:11
Yadi, 

Probably, you can try two directions on solving your problem. 

1. Use repaint(int x, int y, int width, int height) instead of repaint(), 
i.e. re-draw only those area need to refresh.

2. Use mutable Image. create the rectangle Image, and draw them up at the 
initalization stage. When you paint on the actual canvas display's 
graphics, just use the API drawImage(Image img, int x, int y, int anchor).

Hope that it can help you a bit.

Shen Bo

> Hallo all,

Last month I developed games application, because I was participating in 
the
SIEMENS J2ME contest in my country. But poor me, I have lost.
By the way, I have problem to draw a picture in J2ME, because J2ME only
recognize PNG format, so if I drawn a picture with PNG format in
application, it will give a picture with rectangle shape. So to solve that
problem, I decided to develop an application to recognizing information
colors value from the bitmap format and the result I moved it into array In
java.
Here's the sample :

private short[] dog5 = { // 12 x 16 pixel
255,255,255,255,53,172,230,41,157,255,255,255,
255,255,255,134,139,113,91,154,67,218,255,255,
255,255,255,121,126,99,150,44,43,102,255,255,
255,255,222,94,62,86,149,48,9,63,255,255,
255,255,255,18,36,128,154,195,149,79,173,255,
255,255,255,66,65,175,184,195,102,61,42,138,
255,255,168,19,101,109,102,184,81,6,53,82,
255,255,222,14,22,20,38,158,170,168,129,91,
255,255,228,51,41,12,4,64,126,137,54,168,
255,255,130,28,162,117,13,22,35,33,70,255,
255,255,78,35,130,128,161,68,63,134,255,255,
255,217,46,121,112,46,109,82,117,255,255,255,
255,206,35,161,143,44,56,98,157,255,255,255,
255,228,34,131,153,62,70,72,105,255,255,255,
166,125,35,57,70,57,55,22,30,156,255,255,
113,35,32,42,29,36,35,25,34,84,255,255, };

// 255 is white and 0 is black
//here's the implementation

int x = 0;
for (int i=posx-jumpHeight;i < 16+posx-jumpHeight;i++)
  for (int j=posy;j < 12+posy;j++) {
       color = dog5[x];
       x++;
       // if the color is white(255) don't draw it. So, it wont give a
rectangle shape result
       if (color != 255)

            g.setColor(color,color,color);
            g.drawLine(j,i,j,i); }
}

But its still has a problem, the problem is the application become slow.
My question : is there any better (ways) to solve that problem ?


Thanks in advance

Yadi.


---------------------------------------------------------------------------
-

 Ikuti polling TELKOM Memo 166 di www.plasa.com dan menangkan hadiah 
masing-masing Rp 250.000 tunai

 --------------------------------------------------------------------------
--

  Return to Index