Alpha blending - T2D VisibilityLevel doesn't work?
by D. Robert Duke · in Torque X 2D · 04/22/2008 (12:44 pm) · 4 replies
I don't believe T2DSceneObject.VisibiltyLevel does anything. It controls the alpha blending in TXB properly but has no effect in game.
Has anyone had success modifying a sprite's alpha during runtime? Is there some alternate method I'm missing?
Here are my steps:
- Create the 2D Starter project
- Open its level in TXB, change the logo's VisibilityLevel to 0.5
- Run it and witness the lack of blending
I've attempted to trace it through the TX source but I get lost in the rendering code.
Has anyone had success modifying a sprite's alpha during runtime? Is there some alternate method I'm missing?
Here are my steps:
- Create the 2D Starter project
- Open its level in TXB, change the logo's VisibilityLevel to 0.5
- Run it and witness the lack of blending
I've attempted to trace it through the TX source but I get lost in the rendering code.
About the author
#2
Of course, this modifies the material, so if you had multiple sprites and you only want some of them translucent you have to make a separate material. I did this in my game and it works fine. But if you needed individual objects to fade in/out you'd need a different material for each object. Or you'd need VisibilityLevel to work.
Thanks for the quick reply Scott.
04/22/2008 (5:34 pm)
Ah, that helps. I'm able to use (SceneObject.Material as GarageGames.Torque.Materials.SimpleMaterial).Opacity and it seems to work with or without IsColorBlended = true.Of course, this modifies the material, so if you had multiple sprites and you only want some of them translucent you have to make a separate material. I did this in my game and it works fine. But if you needed individual objects to fade in/out you'd need a different material for each object. Or you'd need VisibilityLevel to work.
Thanks for the quick reply Scott.
#3
maybe this would be better than my first idea:
Don't set Opacity on the material as I originally posted. Then set the visibility level on individual sprites. I put two logos in the scene and set one with visibilty level 1.0 and one with 0.5. That worked for me.
04/22/2008 (5:48 pm)
Ah,maybe this would be better than my first idea:
<SimpleMaterial name="GGLogoMaterial" type="GarageGames.Torque.Materials.SimpleMaterial">
<TextureFilename>data/images/GGLogo.png</TextureFilename>
<IsTranslucent>true</IsTranslucent>
<IsColorBlended>true</IsColorBlended>
</SimpleMaterial>Don't set Opacity on the material as I originally posted. Then set the visibility level on individual sprites. I put two logos in the scene and set one with visibilty level 1.0 and one with 0.5. That worked for me.
#4
04/22/2008 (5:54 pm)
Very nice, it works! I take back everything bad I said about VisibilityLevel.
Torque Owner Scott Goodwin
in the levelData.txscene file:
<SimpleMaterial name="GGLogoMaterial" type="GarageGames.Torque.Materials.SimpleMaterial"> <TextureFilename>data/images/GGLogo.png</TextureFilename> <IsTranslucent>true</IsTranslucent> <IsColorBlended>true</IsColorBlended> <Opacity>0.5</Opacity> </SimpleMaterial>The key seems to be IsColorBlended needs to be set.