Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Fadingin in and out  (Read 2677 times)
0 Members and 1 Guest are viewing this topic.
Offline danielmfreitas

Senior Newbie




Java games rock!


« Posted 2005-03-12 13:49:54 »

Is it possible to create a fade effect in MIDP2? I have a screen showings stuff with LayerManager. Then I need to change to another screen (like the player entering a city). The screen would then fade out, and fade in inside the city.
Offline davidaprice

Junior Member





« Reply #1 - Posted 2005-03-15 05:14:22 »

Theoretically it would be possible using Image.getRGB and Image.createRGBImage (names from memory: no JavaDoc on this PC). But you'd need to create a new image for each step of the fade, which is probably prohibitive.

What you'd need is a new method something like:

 graphics.drawImage(myImage, x, y, alpha);

This might be a good thing to ask for from MIDP 3. Why not ask for it on KVM-INTEREST? They're gathering MIDP 3 requirements there right now.
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #2 - Posted 2005-03-15 08:07:32 »

While it would be nice to see full alpha support in MIDP3, you can do a cross-fade in MIDP2 without much trouble at all.

1  
Graphics::drawRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height, boolean processAlpha)

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davidaprice

Junior Member





« Reply #3 - Posted 2005-03-15 09:00:05 »

Not bad. I really should put the JavaDocs on that PC at home.

Abuse: have you actually used this technique? Seems like you'd have to modify the alpha value of each pixel in your RGB array for every step of the fade. Does that run fast enough for smooth fades, on real phones?
Offline ribot

Junior Member




Ribot - mobile UI specialist


« Reply #4 - Posted 2005-03-15 09:21:25 »

From my experience, the drawRGB method needs to be sped up by a number of magnitudes before it can really be used (for fullscreen fades).  Something that I have done for fullscreen fade in and outs is as follows:

1) Create an image out of RGBA values - make sure that its width fills the whole screen, but make sure its height is no more than 27 pixels.  You can't create immutable images with arrays larger than 4096 length.

2) Save the image data into an immutable image for use later.

3) Go back to step 1, but increment the opacity value.

4) The result - you end up with an array of small immutable images which are relatively fast to draw.

Now, when you wish to do a fade, just fill the screen with 8 of the currently selected immutable images.  Your logic code will progress the array counter to select the next more or less opaque image in 100 milliseconds or whatever.

Works for me.

Regards,

Ribot

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #5 - Posted 2005-03-15 09:43:05 »

nope, I havn't done it myself, but I'm quite sure it'd be fast enough.

I was actually thinking of just fading between the 2 images rgb values, the alpha would play no part in it.

Quote

You can't create immutable images with arrays larger than 4096 length.


Sounds ike a handset issue???

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline ribot

Junior Member




Ribot - mobile UI specialist


« Reply #6 - Posted 2005-03-15 09:47:50 »

"Sounds ike a handset issue" - it affects all recent MIDP2.0 series 60 phones.  Sad

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Offline danielmfreitas

Senior Newbie




Java games rock!


« Reply #7 - Posted 2005-03-15 10:24:58 »

I'll try the drawRGB to see how it performs. Anyway, I'll just be sure to create other types of "fades", like striping out, squaring out etc.
Offline wooD

Senior Newbie




J2ME Developer


« Reply #8 - Posted 2005-03-15 21:01:44 »

How about using setClip to only draw small 2x2pixel or 4x4 pixel sections of the image in random order over a specific amount of time into an offscreen bitmap. Keep track of which ones have been drawn so far and then over time the complete image will appear to fade in.

Wood

Offline Falken

Senior Newbie




biggidy bong


« Reply #9 - Posted 2005-03-15 22:25:17 »

Fading can be done very cheaply on Nokia devices just by using DirectGraphics.fillPolygon().   Simply paint your graphics as normal but afterwards draw a rectangle (using fillPolygon) to cover the entire screen.  This is drawn using an ARGB color so by slowly modifying the alpha component every frame you can fade the polygon in or out.   This is a nice and cheap trick - but sadly it only works with the proprietary Nokia API.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #10 - Posted 2005-03-15 22:41:26 »

Quote
Fading can be done very cheaply on Nokia devices just by using DirectGraphics.fillPolygon().   Simply paint your graphics as normal but afterwards draw a rectangle (using fillPolygon) to cover the entire screen.  This is drawn using an ARGB color so by slowly modifying the alpha component every frame you can fade the polygon in or out.   This is a nice and cheap trick - but sadly it only works with the proprietary Nokia API.


I believe the poster was after a cross fade between 2 images, not a fade to color.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Falken

Senior Newbie




biggidy bong


« Reply #11 - Posted 2005-03-15 23:30:26 »

Yes that's right, sorry, it will only fade between the polygon color (eg. blackness) and whatever is being drawn underneath.   Admittedly it is rather limited, especially as it requires the Nokia API, but it can be a simple and cheap alternative if you don't mind it fading-out to black.  Once the black polygon is fully opaque you can switch the graphics underneath before fading back in to slowly reveal the new screen.
Offline danielmfreitas

Senior Newbie




Java games rock!


« Reply #12 - Posted 2005-03-16 14:12:11 »

Oh dear!

I should have said that the screen would fade to BLACK, and then fade in inside the city. Falken gave me the solution. Thx. Maybe we should ask for gamma support in kvm-interest? So fading to black would be easy, just decreasing the gamma until the screen is completely balcked out. Then, add gamma gradualy until is returns to its default value.
Offline ribot

Junior Member




Ribot - mobile UI specialist


« Reply #13 - Posted 2005-03-16 14:39:54 »

Nice to know the solution!  How did you find the performance of the fillPolygon method?  If you don't mind, what devices have you tested on and what gap in time and alpha have you found good for a smooth fade?

http://ribot.co.uk - design agency focused on mobile
http://www.retrospecs.co.uk - online vintage eyewear store
Offline davidaprice

Junior Member





« Reply #14 - Posted 2005-03-17 06:37:41 »

Quote
Maybe we should ask for gamma support in kvm-interest?


I think you should. It's already on my list of things to bring up with our Expert Group members; what I have in mind is:
 graphics.drawImage(image, x, y, anchor, alpha);
Then you could vary the alpha with each redraw to do a corss-fade. Another thing on my list is:
 graphics.setARGBColor(r, g, b, alpha);
 graphics.setARGBColor(argb);  // 0xaarrggbb
That's already in the Nokia UI API, so clearly easily implementable at least for Nokia Wink. And that would allow you (by setting colour to 0xaa000000 and filling a rectangle) to do the fade to/from black.

MIDP 2.0's support for transparency in PNGs states that you either support alpha fully, or treat anything other than full transparency as fully opaque. I'd like to propose the same principle for the possible wider transparency support MIDP 3.0 (e.g. the methods above) so that it wouldn't be too much of a burden for the least powerful phones. Otherwise the manufacturers might have to veto the whole thing. Would that be acceptable to you lot?
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #15 - Posted 2005-03-17 07:19:46 »

Why limit alpha'ed drawing to drawImage?
An alpha global to a Graphics context would be alot more useful. (alpha'ed fillRects, and drawLines for example)

1  
2  
3  
4  
/*
 * @param value Valid range of values 0 to 255
 */

setAlpha(int value)

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline davidaprice

Junior Member





« Reply #16 - Posted 2005-03-17 09:25:37 »

You'd get alpha'd fillRects and alpha'd drawLines from that setARGBColour method, by setting the current colour to a colour with the right alpha component.

I agree that a setAlpha instead could then be taken to apply to drawImage as well, removing the need for a new drawImage method with an alpha parameter. Either would be fine. But I like the idea of emphasizing the concept of colour naturally having an alpha component.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!