| Reply | « Previous Thread | Next Thread » |
|
Hi,
after a lot of weeks of fustrating attempts to draw sprites with transparency on the series 60, yesterday an Angel came to my room and made me realise that there´s a solution ! And I feel great because I think it will help many of you. Well, it´s not the cleanest method, but it works ! This problem happens to be in some S60 models, depending on the firmware version. It´s a matter of the getGraphics method, for it always return the Graphics object of the Canvas, and not the Graphics context of the image we want to get the pixels from. So, if you can´t beat your enemy ... join him ! Draw the image with the sprites in the Canvas object and get the sprites from it, and since it does double buffering, before the paint method ends, erase the image from the graphics context. In other words, this would be an example: protected void paint(Graphics g){ if(firstTimeHere){ getSprites(g); firstTimeHere=false; }else { do the normal painting } } private void getSprites(Graphics g){ g.drawImage(spritesImage,0,0,Graphics.LEFT|Graphics.TOP); DirectGraphics dg=DirectUtils(g); dg.getPixels(ballArray,x,x,x,...); dg.getPixels(.....); ... // This is important, if we don´t want the image to be shown on the screen: g.setColor(0x00FFFFFF); g.fillRect(0,0,this.getWidth(),this.getHeigh()); } I hope it helps ! |
|
Hi,
its fine, but I need use getPixels many many times, so make it as you made it is impossible. Dou you have any idea how to make it? I need to use getPixels for getting a color from only one pixel...but many times... |
|
nyakete, nice and tricky solution :)
Just an idea that can also be helpful. If you don't have really huge amount of sprites you can provide them in a form of pixels array before application launches ;) That is: I prepare files containing pixel arrays and include them to jar file. It's not that complex, because some Nokia formats are very close to bmp stucture. |
|
So, can anyone help me?:-)
|
|
mmm, I thought that once I´d have the sprites caught, with getPixels, the rest would be easy and would work. But now there´s the problem of transparency.
I´ve tried using the ALFA channel, and it doesn´t work yet. I´ve tried it manually, setting the 0xF000 value in the pixels I want transparent ... but no success. I´ll keep trying. |
|
There are 4 bits for transparency, so 16 levels of transparency only. So sets of 16 values between 00-FF would map to the same transparency level.
[N]/Forum Nokia |
|
nmittal, you meant probably 16 values from 0 to F
|
|
maybe i got this wrong but you can actually paint transparent sprites on s60.
transparency is enabled in immutable images (see midp api docs). so if you load your sprites from a gif file with transparency, you can simply use drawImage and it will retain transparency. if you have multiple frames of animation or simply multiple sprites within a single gif file, use setClip to bound the area drawn by drawImage. /jascha |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|