|
entity - entity handle alpha# - transparency level, 0 to 1; 1 (default) |
|
Sets how transparent an entity is. An alpha of 1 is fully opaque and is the default; 0 is completely see-through; values in between give partial transparency, which is how you get glass, water, ghosts, force fields and fading-in pickups. Setting alpha below 1 switches the entity to alpha blending automatically - you do not need EntityBlend as well. That also means it becomes a transparent object as far as rendering is concerned: transparent surfaces are drawn after solid ones and are not depth-sorted perfectly against each other, so two overlapping transparent objects can pop in front of one another as the camera moves. EntityOrder gives you manual control when that matters. Alpha 0 is worth knowing about on its own. The entity is not drawn, but it still takes part in collisions - unlike HideEntity, which removes it from collision tests altogether. That makes alpha 0 the right choice for invisible collision geometry, trigger volumes and clip brushes, and HideEntity the right choice for things that are genuinely out of play. Entity alpha multiplies with the alpha a brush or texture already carries, so a half-transparent texture on a half-transparent entity ends up at a quarter. See also: EntityBlend, EntityColor, EntityOrder, HideEntity, BrushAlpha. |
; EntityAlpha Example
; -------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
light=CreateLight()
RotateEntity light,45,45,0
; A red wall behind the ghost cube, so the transparency is visible
wall=CreateCube()
ScaleEntity wall,6,2,0.2
PositionEntity wall,0,0,8
EntityColor wall,255,0,0
; The ghost cube whose alpha we will change
ghost=CreateCube()
PositionEntity ghost,0,0,5
alpha#=1.0
While Not KeyDown(1)
; Press + / - to change the alpha level
If KeyDown(13) And alpha<1 Then alpha=alpha+0.01
If KeyDown(12) And alpha>0 Then alpha=alpha-0.01
; Apply the transparency to the ghost cube
EntityAlpha ghost,alpha
TurnEntity ghost,0,1,0
; Arrow keys move the camera
If KeyDown(200) Then MoveEntity camera,0,0,0.1
If KeyDown(208) Then MoveEntity camera,0,0,-0.1
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
RenderWorld
Text 0,0,"+ / - : change alpha Arrows: camera Esc: exit"
Text 0,20,"EntityAlpha ghost,"+alpha
Flip
Wend
End