alpha on rectangles
Blitz3D Forums/Blitz3D Programming/alpha on rectangles
| ||
probably an easy question: Is there a way to make a rectangle that is slightly transparent, without having to use writepixelfast? |
| ||
Use the EntityAlpha command to change the transparency of an entity. |
| ||
I can only use EntityAlpha that with 3d objects I think. I am currently using the Rect command to draw a rectangle on screen to house the buttons and in-game map. If I try to put rect into a variable, I get an error, so is there a rect command that works in a variable or something? |
| ||
Nah you can't really assign a var to a rectangle in the way you would 3d entities. For ease you could use a dithered image of a rectange making every second pixel black. 1010 0101 1010 Not really the same as alpha though but would appear to be see-through. |
| ||
Could I use writepixelfast for this? It seems to use a colour method that includes alpha. But how does that colour assignment system work? |
| ||
You might want to take a look at the sprite transparency code that Ford Escort made, you will find it here: http://www.blitzbasic.com/codearcs/codearcs.php?code=913 |
| ||
You just need to blend the pixels of the rectangle with whatever is behind it. Yes writepixelfast would work. |
| ||
Can't I just set alpha in the colour information when I call writepixelFast? |
| ||
Oopz, now I see what your getting at. Mind you, doing this with 3D would be much faster, all you need to do is... 1. create a 3D sprite 2. position the sprite where you need it. 2. texture it with your graphics. 3. set your alpha value with EntityAlpha(). 4. lock it to the camera with EntityParent(). 5. use EntityOrder() with a value of -1 so its alway drawn on top. IMHO it's better not to use 2D on top of 3D, because some graphics cards struggle with it. Also if you intend to have a choice of screen resolutions, doing it with 3D means your HUD will always fit the screen as you intended, no matter what the resolution. And it will save a lot of process time, WritePixelFast is SLOW for realtime graphics. BTW I'm assuming your writing a 3D game, apologies if your not ;) Hope this helps. |
| ||
I am doin ga 3d game. It will only need to run on a few computers though. I now assume that using sprites would be easier though, so I'll do that. |
| ||
okay, I tried using a sprite, but I can't get it working right. The sprite is not visible;create the camera Global camPointer = CreatePivot() PositionEntity camPointer,640,72,1895 TurnEntity campointer,0,-135,0,True ;campointerY = TerrainHeight#(terrain,EntityX(Campointer),EntityZ(CamPointer)) * 128 ;PositionEntity camPointer,500,campointerY,700 Global cam = CreateCamera(camPointer) MoveEntity cam,0,80,-100 CameraFogMode cam,1 CameraFogColor cam,150,150,150 CameraFogRange cam,300,1024 ;the sprite for the background of the buttons buttonbg = createsprite(cam) scalesprite buttonbg,graphicswidth() - 20,130 entitycolor buttonbg,0,0,0 positionentity buttonbg,entityx(cam),entityy(cam),entityz(cam) ;pointentity buttonbg,campointer moveentity buttonbg,0,0,2 ;note that I've tried many distances for this, up to 10. What am I doing wrong? |
| ||
You were positioning the sprite too far away from the camera. The positionentity command is at local coords remember. You're scaling the sprite v big unecessarily. You were also colouring the sprite black so you wouldn't see it anyway. Try this ... Graphics3D 640,480,16,1 ;create the camera Global camPointer = CreatePivot() PositionEntity camPointer,640,72,1895 TurnEntity campointer,0,-135,0,True ;campointerY = TerrainHeight#(terrain,EntityX(Campointer),EntityZ(CamPointer)) * 128 ;PositionEntity camPointer,500,campointerY,700 Global cam = CreateCamera(camPointer) MoveEntity cam,0,80,-100 CameraFogMode cam,1 CameraFogColor cam,150,150,150 CameraFogRange cam,300,1024 ;the sprite for the background of the buttons buttonbg = CreateSprite(cam) ScaleSprite buttonbg,1,.5 EntityColor buttonbg,100,100,100 PositionEntity buttonbg,0,0,1 While Not KeyDown(1) RenderWorld() Flip Wend Hope this helps. Stevie |
| ||
thanks for that, it works nicely. |