Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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  
  How are the images used correctly in 2D? (gif or png?)  (Read 1419 times)
0 Members and 1 Guest are viewing this topic.
Offline tonberry1

Junior Member





« Posted 2005-06-08 10:05:24 »

Im wondering, how is the transparency made to games usually?

If I use png, the graphics work perfectly: I can use translucency (that half-transparent thing), but the really big minus is, that my game's fps dropped to 1-3, which is way too slow.
--> The game with png images

If I use gif, the fps is good, something like 50-70, but the picture looks like it would have been made with chainsaw.
--> The game with gif images
(notice the tree line near the sky and the bushes at the bottom, ball and players arent gifs, because those are small enough pictures to use pngs)

It feels like Im missing something..

-= Life is what you decide it to be - Solid Snake =-
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #1 - Posted 2005-06-08 14:49:08 »

PNG can also do indexed images.

So, the question isn't if you should use gif or png... instead it's if you should use full alpha or bitmasked transparency. Bitmasked is of course faster... but.... well there is no reason that it needs to look that bad. Your screenshot looks like you only set the fully transparent bits to transparent and the rest to opaque (and it was also blended to a white background before). Well, that doesn't work (apparently).

Usually you would need to use some kind of treshold - 50%. Less than that = opaque and more than that = transparent. Your drawing programm should do stuff like that automatically, if you save a full alpha image as gif or 8bit png. However, you could also do that at runtime (if you want to give the user the ability to switch between fullalpha and bitmasked). All you need to do is copying the image over to a bitmasked image.

弾幕 ☆ @mahonnaiseblog
Offline woogley
« Reply #2 - Posted 2005-06-08 15:03:28 »

well, just in case you don't know, there are 3 different types of transparencies in Java:

  • Opaque - all pixels are visible (no transparent pixels)
  • Bitmask - all pixels are either 100% visible or 100% transparent (no middle-ground here)
  • Translucent - pixels can be partially visible and partially transparent

Now there's a difference between GIF and PNG. GIFs can only save in the opaque or bitmask mode. It doesn't support translucent pixels. PNG, however, supports all 3 transparencies. The problem with your FPS is hardware acceleration.

Hardware acceleration makes use of your video card and speeds up Image processing. One way to create an accelerated Image is to use this method from the GraphicsConfiguration class:

1  
createCompatibleImage(width,height,transparency);


That last parameter is an int provided by the Transparency class. You can use either Transparency.OPAQUE, Transparency.BITMASK, or Transparency.TRANSLUCENT

The problem is Java only supports acceleration for BITMASK and OPAQUE - which is why your PNG with translucent pixels chokes the FPS. Not to mention it takes alot of computing power anyway to composite translucent pixels.

There are a few things you can try to get around your problem:

  • Don't use transparency for your mountains. If the background image doesn't change in some way, there's no reason for the transparency in the mountains. Save the mountains with the same color background that the real background uses
  • Enable the OpenGL pipeline (Java 1.5 only) by passing this option in the command-line: -Dsun.java2d.opengl=true
  • Use an OpenGL library (LWJGL, Xith3D, jME, etc.) - These libraries give you access to OpenGL's capabilities. The OpenGL is all hardware accelerated and OpenGL can handle translucency much more decently than average Java
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tonberry1

Junior Member





« Reply #3 - Posted 2005-06-09 16:43:43 »

Don't use transparency for your mountains. If the background image doesn't change in some way, there's no reason for the transparency in the mountains. Save the mountains with the same color background that the real background uses[/li]
Actually the sky is moving, so thats the reason why the mountains are translucent. But I figured I could raise the clouds a little bit, so I could use even jpg-images as the mountains.
Quote
  • Enable the OpenGL pipeline (Java 1.5 only) by passing this option in the command-line: -Dsun.java2d.opengl=true
  • Use an OpenGL library (LWJGL, Xith3D, jME, etc.) - These libraries give you access to OpenGL's capabilities. The OpenGL is all hardware accelerated and OpenGL can handle translucency much more decently than average Java
Thanks, that looks like something that will be useful. Ill be back after I have checked those.
Quote
Your drawing programm should do stuff like that automatically, if you save a full alpha image as gif or 8bit png. However, you could also do that at runtime (if you want to give the user the ability to switch between fullalpha and bitmasked). All you need to do is copying the image over to a bitmasked image.
I know that this game is also going to be played/tested with slower machines than mine, so that might be a good thing to do also Smiley

-= Life is what you decide it to be - Solid Snake =-
Offline tonberry1

Junior Member





« Reply #4 - Posted 2005-06-09 17:23:14 »

Problem solved, the solution was to activate the hardware acceleration (-Dsun.java2d.opengl=true), now the game runs smoothly even with all those translucent images, tho I think I do as you suggested and change the format etc.

But another problem: The game wont go to full-screen mode anymore.

Of course the problem might be in the class which I use to go into full-screen mode, but if this is a common problem, Id appreciate to know it (and/or the solution) Smiley

-= Life is what you decide it to be - Solid Snake =-
Offline Rickmeister

Senior Member


Medals: 9
Projects: 1
Exp: 15 years


Don't eat yellow snow!


« Reply #5 - Posted 2005-06-16 02:04:58 »

I've had this problem too, and as far as I know this is a known bug. But there is a way around it.

Instead of setting the DisplayMode manually, you should use the GraphicsDevice.getDisplayModes (returns an array of all available displaymodes that your hardware supports) and then pick a suitable one from that list. Simple as that  Cool

This is a link to my post about OpenGL and Fullscreen exclusive mode
http://192.18.37.44/forums/index.php?topic=4953.msg45074#msg45074
Offline tonberry1

Junior Member





« Reply #6 - Posted 2005-06-16 10:50:20 »

Instead of setting the DisplayMode manually, you should use the GraphicsDevice.getDisplayModes (returns an array of all available displaymodes that your hardware supports) and then pick a suitable one from that list. Simple as that  Cool
Thx very much. I havent tested that yet, but I choose that mode manually, so I think that solution will work Smiley

-= Life is what you decide it to be - Solid Snake =-
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.

xsi3rr4x (18 views)
2014-04-15 18:08:23

BurntPizza (15 views)
2014-04-15 03:46:01

UprightPath (28 views)
2014-04-14 17:39:50

UprightPath (13 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (54 views)
2014-04-10 04:04:31

BurntPizza (111 views)
2014-04-08 23:06:04

tom_mai78101 (212 views)
2014-04-05 13:34:39

trollwarrior1 (181 views)
2014-04-04 12:06:45

CJLetsGame (187 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!