HUD Alpha help please.
Blitz3D Forums/Blitz3D Programming/HUD Alpha help please.
| ||
Allow me to bug you smart people with a simple issue I am having. What I am after is displaying a HUD image on the screen. That part works great, and it cuts out all the black like I want. But now I want the visible part to be semi-transparent. Here is my code; ;Load HUD hud=LoadImage("./images/hud1.bmp") MaskImage hud,0,0,0 DrawImage(hud,1,657) So I thought I could get away with; EntityAlpha hud,.5 You guessed it, that does not work. So how do I get my HUD image to be semi-transparent? thanx to anyone who can help :) |
| ||
Well, firstly, drawing images 'with alpha' can be very costly (regarding frames per second). You'd probably want to write some code to align sprites to the viewport (it's not hard) and then use the sprite's properties (e.g., EntityAlpha, EntityFX, etc.) to make it look funky in some way or another. Just as a suggestion, the technique I use is composed of about two parts: 1. 'Initialize' the aligner. Stick a plane in front of the player, give it a pickmode (2 is best, probably), and then get the XYZ coordinates of the pixels 0,0, the XYZ coordinates of ScreenWidth,0, and the XYZ coordinates of 0,ScreenHeight. And then Pseudo-code: Function InitAlign(Camera) Create the plane rotate the plane so it's aligned with the camera's angle position the plane at the camera's position turn the plane by -90 along its pitch pick 0,0 pick graphicswidth(),0 pick 0,graphicsheight() create a pivot (refer to it as PivA) place PivA at the coordinates of the 0,0 pick create another pivot (refer to it as PivB) place PivB at the coordinates of the graphicswidth(),0 pick point PivA at PivB parent PivA to Camera free PivB DistanceZ# = the distance between the 0,0 pick and the graphicswidth(),0 pick and store it somewhere, maybe in a global variable DistanceY# = distance between the 0,0 and 0,graphicsheight() picks return PivA End Function And your function should be called before the camera is rotated, angled, etc. Otherwise, it'll screw up (probably). 2. Whenever you need the coordinates of something: Function AlignToCamera(PivA,X,Y) z_mov# = (X/graphicswidth())*DistanceZ y_mov# = -(Y/graphicsheight())*DitanceY ;negative 'cause 2d positive goes 'down' and 3d positive goes 'up' moveentity PivA,0,y_mov,z_mov PivC = create a pivot and stick it at the position of PivA moveentity PivA,0,-y_mov,-z_mov ;move it back so it's reuseable return PivC End Function And there you have a (there's code in Vein for these operations, but it needs tweaking) basic example of how to get the positions. Then, you just stick a sprite there (and you'd probably want to get the positions of the x+width and y+height of the image so you can scale the sprite accordingly) and perform whatever operations on it. And parent it to the camera so it doesn't move, too.. Hope that was understandable. |
| ||
LoadImage, DrawImage and it's like are strictly 2D commands and do not support alpha. It's generally not a good idea to mix 2D and 3D anyway (due to speed issues with certain hardware). The simplest method for a 3D HUD would be to use sprites parented to the camera (and probably entityorderd to render last) Have a look in the code archives. There should be a couple of examples of HUD code. YAN |
| ||
Hello, @Noel Cower Sure, it all makes sense, now it's time to stay up all night and see if I 'actually' understand it and can integrate it into my game. @Yan I'll take a closer look, I looked earlier and I did not find anything, or at least that made sense to me :) Anyway, thanx a bunch for the posts, I'm sure the solution is in there. |