Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
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 4500 times)
0 Members and 1 Guest are viewing this topic.
Offline stonedyak

Junior Newbie

Java games rock!

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


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 Devvie

Thick As A Brick

« Reply #1 - Posted 2002-11-12 12: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 13: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 Devvie

Thick As A Brick

« Reply #3 - Posted 2002-11-12 14: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 20: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 15: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.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

theagentd (98 views)
2017-02-18 13:42:33

theagentd (102 views)
2017-02-18 13:35:16

h.pernpeintner (1267 views)
2017-01-24 22:39:11

h.pernpeintner (1256 views)
2017-01-24 22:38:32

Galdo (1816 views)
2017-01-12 13:44:09

Archive (1920 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2458 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2297 views)
2016-12-15 21:50:57

Lunch (2376 views)
2016-12-06 16:01:40

ral0r2 (2155 views)
2016-11-23 16:08:26
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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‑
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!