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 (536)
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  
  volatile image with bitmask transparency?  (Read 2867 times)
0 Members and 1 Guest are viewing this topic.
Offline stonedyak

Junior Newbie




Java games rock!


« Posted 2002-11-12 11:47:24 »

Hi,

I'm making a platform type game, and I've got fullscreen scrolling sorted so far. However I'd like to add some background layers that move more slowly than the scrolling platform layer to give a feeling of depth (i.e do parallax) .

I'm currently blitting the platform layer to a seperate VolatileImage. My problem is that I can't see any way to create a transparent VolatileImage so that my background layers will show though.

I've found createCompatibleImage(int width, int height, int transparency) but there seems to be no equivalent for a volatile image - only  createCompatibleVolatileImage(int width, int height).

Is there any way to do this?
Offline zparticle

Senior Member




Thick As A Brick


« Reply #1 - Posted 2002-11-12 13:44:56 »

I think what you want to do here is blit the background layers into the same VolatileImage you use for the platform layer.

Do the background layers first and then the platform layer.

If the "tiles" for the platform layer contain transparent areas the background layers will show through.

Then blit the entire thing to the screen.

Offline stonedyak

Junior Newbie




Java games rock!


« Reply #2 - Posted 2002-11-12 14:22:47 »

yeah, I thought of that. However that's not ideal, because of the way I do my scrolling.

The actual platform layer only scrolls by a whole tile width at a time. I do pixel scrolling by changing the offset of the layer when I blit it to the screen. This means that the platform layer only gets redrawn every time I scroll past the edge of a tile (say 1 in 16 frames). Even then, only a bit of it gets redrawn, since I use a copyArea to move the part that stays onscreen and just draw the newly visible row or column of tiles.

Would I have to scrap that way of doing things if I want parallax?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zparticle

Senior Member




Thick As A Brick


« Reply #3 - Posted 2002-11-12 15:24:57 »

Yeah I'm pretty sure you will will have to redraw the entire thing every frame to get your parallax to work. I had this same problem and redrwaing everything everyframe was the only solution I could find.

Perhaps someone else has a better way to do this. I found that I could still peg the frame rate, even when drawing everything, so for me it wasn't an issue.

Obviously you don't need to redraw the background when there isn't any scrolling occuring, you reblit the frame you drew last time to the screen (unless the volitale image is invalidated).


Offline stonedyak

Junior Newbie




Java games rock!


« Reply #4 - Posted 2002-11-12 21:52:23 »

that's a shame. and I was quite pleased with that scrolling routine  Roll Eyes

I guess it won't really matter redrawing everything with hw acceleration on windows, however I'd like it to run well on Linux as well. Without acceleration, every blit matters.

Any other ideas welcome!
Offline chet

Senior Newbie




Java games rock!


« Reply #5 - Posted 2002-11-13 16:21:53 »

In answer to your first question, there is unfortunately no way to create a VolatileImage that is non-opaque (translucent or transparent).  This is API that we should introduce in jdk1.5 (a ways off, but I just thought I'd mention it).  The main idea behind the first VolatileImage API was to have the ability to force the back buffer to live in hardware.  Back buffers are usually opaque, so this simple API did the trick.  Now that that functionality is there, we can beef up the Volatile API to include other related operations/formats that people care about.

As to how you work around the issue, you should be able to use createCompatibleImage(w,h,transparent) for any background which will remain static.  Say you have a scrolling starfield (or whatever); you can create this as a compatible image and simply copy from there into your Volatile back buffer.  At some point (usually the second copy), we will recognize this as something that we can do better in hardware and we will create a VRAM version of that compatible image to use from then on.  As long as you are not touching the pixels of the compatible image, we will continue to use the VRAM version of it and you will get native-hardware speeds.

Things to watch for:
- DO NOT grab the Raster or DataBuffer for the compatible image.  If you do this, we give up on accelerating that image because we cannot guarantee that our VRAM version matches the original image (because you can tweak the pixels directly without our knowing).  We will probably introduce some sort of Lock/Unlock API for this in the future, but for now just avoid it if at all possible.
- Accelerating compatible images only works for opaque and transparent images for now.  We're working on translucency acceleration; this should be there in jdk1.5.
- There can be problems with images larger than the screen size (we may not be able to create a VRAM image larger than that size), so if you need a background image larger than this, you'll have to tile it into several images.

Hope that helps.

Chet.
(Java2D)
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.

Riven (19 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (31 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

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

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

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

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

ctomni231 (60 views)
2014-07-18 06:55:21
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!