I m trying to make the texture that I,m uploading to disappear over time, Im using this code to do that:
cont = bge.logic.getCurrentController() # cont = the Python controller running this script
obj = cont.owner # obj = The owner of the controller, e.g. this object
if not 'init' in obj: # Initialize object values
obj['init'] = 1
obj.color = [1, 1, 1, 1]
obj['fadeout'] = 1
color = obj.color
rate = 1.3 / bge.logic.getLogicTicRate() # Number of seconds to fade in or out
if color > 0: # Fade out gradually, but only if the color alpha is greater than 0
color -= rate
obj.color = color # Assign the color variable back to the object's color
But for this code to work I need to set key-frames for the diffuse color and the alpha value, also I have to enable the object color option on the material panel.
The problem happen when I enable the object color option, when I press p, the object simply doesnt apear at all.
Anyone knows how can I make that animation?
thanks for your help.
Is it possible to use keyframes on Transparency > Alpha in the BGE with a texture? I’ve tried and I made a new action “fadeOut” and I can set keyframes (right click on the Alpha setting for the material -> Insert Keyframe) for 1.00 and 0.00 some number of frames later. I setup the logic bricks to play the action and with Object Color enabled I get just a black mask of the smoke blast that fades out. No python needed. Without it enabled the plane appears correctly but doesn’t fade when space bar is pressed.
Your code sure works. I imported the image, set the material to have transparency and to use the alpha channel from the image, then set object color to TRUE. I added some logic bricks and pressing spacebar makes if fade out just fine.
Here is what I was playing with trying to help:smoke_blast fadeout.blend (573 KB)
The file contains two scenes - “Key Frame Fade” and “Logic Brick Fade”
Don’t know if it helps but now I want to know the answer from one of the gurus around here.
WOw, thanks downshift, I really didnt knew that multiply trick, untill the 2.59 versions of blender I used it the way I mentioned, well, I think that now this way is easier, well, thanks a lot man, a small detail like that makes my life easier!
Glad it helped!
I’d still like to know from the pros if it is possible to use keyframes for controlling the values of various material settings in realtime. It would be kinda cool to have included in an action for say taking a hit and to make you character flash you could use key frames to set the spec and diffuse amounts up and down rapidly.
Yes it is. You can control materials with actions. Use the action actuator with the material action (ie “MaterialAction”, if your material was called “Material”)
You can use it to control colour, alpha, specular values and such.
Be aware there are:
MaterialActions to control Material transparency (from Matrial to Object color). You need to keyframe the diffuse color as well to make it work.
ObjectActions to control the objects transparency (from Object color to nothing). With that you keyframe the color and alpha in one step as they belong together.
Be aware that GLSL and Multitexture mode behave differently. You can get similar results unfortunately there are still some minor differences at the shading.
I discovered some problems with material/object color actions and transparency and “add” mode. They are hard to describe.
I am on my phone now and can’t post a blend but I tried setting up a test as you described sdfgeoff. I have an action on the default cube just called “MaterialAction” and I have set keframes every 5 frames to make the diffuse reflectivity go from 0.8 to 0.0 repeatedly. In the logic I linked a keyboard looking fr SPACEBAR to be pressed and linked that to the action actuator with MaterialAction set for frames 1 - 21. I start the game engine and it doesn’t work. I’m sure it something simple and I only spent a few minutes on it the other night while taking a break from my main project idea. Any thoughts? I’ll post the blend later if needed.
Not the diffuse reflectivity, but click the “transparency” button, and animate the alpha slider under that.
Thanks for the reply. I got both key framing diffuse color and the transparency to work as you said but only in multitexture mode. GLSL just shows my default cube in the last state that I edited either the color or the transparency and does nothing in the game engine. Switch back to multi texture and it works fine. I’ll keep poking around with it tomorrow.
Try this one it works pretty well with Single Texture, MultiTexture and GLSL ;).
GLSL results in a bit brighter colors. But this might be an issue with the shading (lamps).
FadeOutDemo.blend (165 KB)
Thanks Monster I think that clears it up. It seems there are very few object and material settings that are able to be animated for use in the BGE. (And it seems to be that if you add a keyframe to it and it doesn’t show the yellow marker in the Action editor it probably isn’t going to work.) I was looking into and hoping that a single material could store reference multiple textures which is no problem but then switch them by adjusting values for color/alpha with key frames on the “Influence” section of the Texture options. Oh well, SolarLune’s post on the video texture switching will work fine for me.