Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / see through 2d

Author
Message
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 7th Dec 2009 04:51
Im making a game and i want to have the background of the menu scrolling while i have boxes that are or appear to be see through over them. Not entirely see through just so it appears ghosted or so. I can't think of anyway to go about doing this while the background image is moving. any help is appreciated
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 7th Dec 2009 05:11
One way (which might be unmanageably slow, I don't know) might be to take two bitmaps - one of the background, and one of the foreground. Then scan both images pixel by pixel, and then convert the colour of each pixel of each bitmap back to RGB. Then, if say 300,200 on bitmap 1 is rgb(20,50,80) and bitmap 2 has rgb(40,50,20) for the same point, then go through doing
r3=(r1+r2)/2
g3=(g1+g2)/2
b3=(b1+b2)/2
then the colour of what you want to display on screen would be (r3,g3,b3). Obviously this may be too slow and I don't know if there's a better way, I'm just thinking aloud about what I'd try first personally.

pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 7th Dec 2009 05:32
well i was kind of thinking on that basis but it's really slow. then i thought i would try out memblocks, but it was too confusing. memblocks would probably be the best way. either that or objects. but im trying to prevent from having to do that.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Dec 2009 05:35
This isn't easy, and if you're unfamiliar with memblocks and logic operators it's almost impossible.
I wont go into detail about memblocks, I don't know if you're familiar with them or not and I'm happy to answer any questions, but for now I'll stick to the logic operators.

Camera filters are a great example of what you want to do; they filter the light passing through. A blue filter, for example, only lets blue light through, making red and green objects appear black, and white objects appear blue. Creating such a filter seems complicated but it's really quite simple.

DBC has two logic operators "&" (AND) and "|" (OR). The only operator we'll need for this type of filter is AND.
AND returns all the bits that are shared by both operands.

We can apply a similar filter to RGB values.


"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Dec 2009 05:51 Edited at: 7th Dec 2009 05:59
@Pictionary
I was also baffled by memblocks but they're not too hard. They're worth learning as they are fast and you can manage pretty much anything with them, even sounds and 3D meshes.

A memblock is what it sounds like, a big lump of memory, and it would be a pretty useless lump if it weren't for its header.
A header is like the contents page of a book; it tells you where you can find the data you want and how big each piece of data is.

Data is written to and read from a memblock in bytes, or groups of bytes such as words (2 bytes), double/long words (4 bytes), integers and floats (which I think are both 4 bytes). There's information in the help files about data types and what the different memblock headers are.

The bitmap header basically consists of the height, width and depth of your bitmap. To edit a pixel you need to first convert the 2D coordinate into 1D, because a memblock is just a string of binary data it's not 2D, so (y*width + x) gives the 1D coord. Then you need to multiply that by depth

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Dec 2009 06:08
BUT depth is the BIT depth, not the BYTE depth so you need to divide it by 8 before you use it. I don't understand 16bit colours so I always use 32bit and therefore DWORDs (4bytes) to read and write memblocks.

If you're incredibly smart you might have wondered why colours are 4bytes when RGB only uses 3bytes (255^3), the fourth byte is alpha (transparency), don't get excited though DBC doesn't use alpha.
Another landmine to avoid is that colours are written "little-endian" which means the smallest bit comes first (01 = 2). You'll see what I mean when you get round to writing your filter .

side note: DBC has a third logic operator: NOT "!", it's the same as <> but I think it's faster.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 7th Dec 2009 06:18
haha im pretty familiar with memblocks like when it comes to a byte. it consists of 8 bits. this is the trouble im having with the image though because it is 16 bit which means the color values are words. they only go to 65536. but when it comes to 16 bit 5 bits are red. 5 bits are blue and 6 bits are green. im not sure of how to alter these values the way I want to though. and i already know when it comes to x and y values of an image turned into a memblock it would the 12+(xpos+(ypos*width)*2). the values r the part im having trouble with.
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 7th Dec 2009 06:19 Edited at: 7th Dec 2009 06:21
haha im using 16 bit. i was posting same time as u. it seems like im out of luck then with 16 bit

I know its written bgra. i think the alpha value stays in back doesnt it?
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Dec 2009 06:37
Ah, you'll have to wait until someone who knows about 16bit comes along then.
I think it was discussed before so try searching the forum.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 7th Dec 2009 16:01
What you are asking for sounds quite easy to achieve, so I can't be understanding what you are asking for...

To clarify:

You want a menu of items in the centre of the screen which is transparent so you can see the main background screen scrolling behind it?

Is that correct?

TDK

demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 7th Dec 2009 16:56
Semi-transparent, possibly translucent, is the gist I think more than actual transparency.

Alternate, code-free option - If you have an animation for the background, could you not just animate with the semitransparent boxes?

pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 7th Dec 2009 18:58
translucent was the effect i was going for. i think i have one way of acieving it by faking it with memblocks
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 7th Dec 2009 19:36
Here's one method without memblocks...



TDK

pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 8th Dec 2009 04:17
that actually works really well but i was trying to avoid using objects because of 3d coordinates. and stuff. i have an idea. if it works ill post
Maindric
14
Years of Service
User Offline
Joined: 22nd Jul 2009
Location:
Posted: 8th Dec 2009 05:41
Can't you just load a PNG? Or does DBC not support the alpha in PNG?

Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Dec 2009 08:27
@Maindric
I think DBC only treats black as transparent. The only alpha blending is in 3d (ghosting) unless you create your own routines.

@pictionaryjr
A "poor man's" sort of alpha is to alternate the pixel colors of your 2d image with black pixels. Then paste the image or sprite with transparency. Here's an example of a green square seeming semi-transparent. The scrolling background can be seen through it:



Enjoy your day.
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Dec 2009 13:49
@TDK

You are advertising your code a lot! What was that for?


Isn't it possible to just use ghosted plain objects instead of pasting images using complex and slow maths? (Not criticizing, of course...)

TheComet


Make the paths of your enemies easier with WaypointPro!
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 8th Dec 2009 15:27
Yeah I think that restricting 2D to only 2D is just making things more complicated. 2D is better off served with a side salad of 3D.

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 8th Dec 2009 18:58
Quote: "You are advertising your code a lot! What was that for?"


I just used my project starter program and that info is automatically placed in the dba file it generates. Please pay attention!

Quote: "Isn't it possible to just use ghosted plain objects instead of pasting images using complex and slow maths?"


Erm... that's what the code snippet of mine you commented on did. Please pay att... oops - already said that!

TDK

TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th Dec 2009 12:22
Quote: "Erm... that's what the code snippet of mine you commented on did. Please pay att... oops - already said that!"


Sorry, it seems I was up late last night and only vaguely skimmed over your code.

TheComet


Make the paths of your enemies easier with WaypointPro!
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 10th Dec 2009 16:38
No probs - been there, done that!

TDK

Login to post a reply

Server time is: 2024-05-02 21:04:19
Your offset time is: 2024-05-02 21:04:19