You Are Here:

Community: Developer Discussion Boards

#1 Old Sprites problem in S60 solved ! - 2003-07-09, 17:45

Join Date: May 2003
Posts: 14
nyakete
Offline
Registered User
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 !
Reply With Quote

#2 Old Need use getPixels many times - 2003-07-09, 20:48

Join Date: Mar 2003
Posts: 5
hardwik
Offline
Registered User
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...
Reply With Quote

#3 Old 2003-07-10, 08:02

Join Date: Jul 2003
Posts: 1,094
Location: Finland, Tampere
doctordwarf
Offline
Super Contributor
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.
Reply With Quote

#4 Old help - 2003-07-10, 18:56

Join Date: Mar 2003
Posts: 5
hardwik
Offline
Registered User
So, can anyone help me?:-)
Reply With Quote

#5 Old mmm ... not yet solved - 2003-07-10, 19:58

Join Date: May 2003
Posts: 14
nyakete
Offline
Registered User
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.
Reply With Quote

#6 Old 2003-07-11, 10:36

Join Date: Mar 2003
Posts: 393
nmittal's Avatar
nmittal
Offline
Regular Contributor
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
Reply With Quote

#7 Old 2003-07-11, 10:48

Join Date: Jul 2003
Posts: 1,094
Location: Finland, Tampere
doctordwarf
Offline
Super Contributor
nmittal, you meant probably 16 values from 0 to F
Reply With Quote

#8 Old 2003-11-17, 18:31

Join Date: Aug 2003
Posts: 3
entity23
Offline
Registered User
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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia