This should be a pretty simple fix, so bear with me.
I can’t get the simple effect from the documentation to work. What confuses me, is this code in the “Effects” part of the tonegodGUI documentation
[java]
Effect effect = new Effect(
Effect.EffectType.FadeIn, // The type of effect to use
Effect.EffectEvent.Show, // The event that the effect is associated with
2.2f // The duration of time over which the effect executes (2.2 seconds)
);
effect.setEffectElement(someElement); // The Element to fade into the screen
screen.getEffectManager().applyEffect(effect); // Tell the effect manager to execute[/java]
Which one is used when? If I just want a simple piece of text to fade in, do I create the effect, set the element of the effect, and tell the screen to execute it, or do tell the element to show with effect?
Either way, I can’t get it to work. Do I have to NOT add the element to the screen (I’m pretty sure I do… ), or maybe add and hide it before showing with effect?
Perhaps I’m missing something fundamental here, but if someone has a small sample of code that works with a tonegodGUI effect (starting from the creation of the element to the actual effect being applied) that would be cool
[java]Element myElementWithEffect = new Element(…);
Effect showEffect = new Effect(Effect.EffectType.FadeIn, Effect.EffectEvent.Show, 2.2f);
myElementWithEffect.addEffect(showEffect);
myElementWithEffect.hide(); //if you want it not visible at start
//Somewhere in the code
myElementWithEffect.showWithEffect();//to show it with the FadeIn showEffect
//or
myElementWithEffect.show();//to show it without effect
myElementWithEffect.hide();//to hide it
//or
myElementWithEffect.hideWithEffect();//to hide it with effect if you have setup one like for show event[/java]
You just have to set up effects for a particular event, add it to the element and then the system fire off it when the event occurs.
But you can fire off an exceptional effect manually if you want it only once for example…via the effect manager
If the effect has been added to an element just call :
[java]screen.getEffectManager().applyEffect(effect);[/java]
else, if you create an effect on the fly…be sure to set the target element (which is internally called by the system when you use addEffect(…)) of the effect with :
[java]effect.setEffectElement(someElement); [/java]
Okay, so I’m starting to get it. However, it seems like my effect doesn’t work… Here’s the code
[java]Effect effect = new Effect(
Effect.EffectType.FadeIn, // The type of effect to use
Effect.EffectEvent.Show, // The event that the effect is associated with
10f // The duration of time over which the effect executes (2.2 seconds)
);
I followed your format, I believe. If I comment out the time_info_l.showWithEffect(), it doesn’t show up at all, which is good. If I leave it there, it shows up just as fast, as if no effect were in place. Thoughts?
<span style=“text-decoration:line-through;”>No, it’s just a Label. Weird…
Could I see your full test code please? Maybe something is going wrong higher up (with mine).</span>
SUPER EDIT: I just tested with a panel too, and whaddya know, it works.
Is there something wrong with the Label class? I think I heard tonegod talk about it not being really necessary, just use a regular element instead or something along those lines. Any confirmation on this?
Hey, i got it…it’s a lib issue…
If you setup a background for your label (or a slide effect for example which move all the child elements) you will see that the effect is running as expected but the bitmapText doesn’t follow the element alpha (used in the shader for the fade effect)…
Ok… gonna try and run through the list of stuff I should have already gotten to. Starting with this!
The following code:
[java]
Effect effect = new Effect(
Effect.EffectType.FadeIn, // The type of effect to use
Effect.EffectEvent.Show, // The event that the effect is associated with
2.2f // The duration of time over which the effect executes (2.2 seconds)
);
effect.setEffectElement(someElement); // The Element to fade into the screen
screen.getEffectManager().applyEffect(effect); // Tell the effect manager to execute
[/java]
Runs an effect ONCE against the element (and child elements) you set using setEffectElement. If you are looking for an effect that happens every time an event happens, you will want to add the effect to the element itself, like so:
[java]
Element.addEffect(effect);
[/java]
This associates the effect with the defined event (specified when creating the effect) to the element the effect is being added to. Now, as for the show and showWithEffect methods. show(); bypasses the effect associated with the show event. showWithEffect shows the element using the defined effect. Hide and hideWithEffect work in a similar way. This was a user request ( @madjack ) and I’ve found it quite useful.
@machspeeds said:
Thanks for the explanation now. I've fiddled around with stuff a lot now, and I'm more comfortable using the effects now. Well, mostly. ;-P
I think we talked about this earlier, but just in case, BitmapText class from JME does not support alpha fading, because of the way texture coords are defined using some sort of color comparision in the texture. I have NO CLUE why this was done this way, as it also stops you from rotating text, but alas… we have what we have =(
EDIT: What bothers me the most about this is, the BitmapFont defines the actual texture coords in pixels, the backing images are textures with a defined width and height. A simple x/width, y/height would have produced the proper texCoords and made BitmapText a WHOLE lot more useful. =(
@t0neg0d said:
I think we talked about this earlier, but just in case, BitmapText class from JME does not support alpha fading, because of the way texture coords are defined using some sort of color comparision in the texture. I have NO CLUE why this was done this way, as it also stops you from rotating text, but alas... we have what we have =(
EDIT: What bothers me the most about this is, the BitmapFont defines the actual texture coords in pixels, the backing images are textures with a defined width and height. A simple x/width, y/height would have produced the proper texCoords and made BitmapText a WHOLE lot more useful. =(
I have no idea what you are talking about.
Each character quad has its own colors in the color buffer because each character can have its own color. I have no idea what you are talking about re: texture coordinates.
BitmapText is all kinds of messed up but it doesn’t help anyone to misremember or make up issues that aren’t there.
@pspeed said:
I have no idea what you are talking about.
Each character quad has its own colors in the color buffer because each character can have its own color. I have no idea what you are talking about re: texture coordinates.
BitmapText is all kinds of messed up but it doesn’t help anyone to misremember or make up issues that aren’t there.
Seriously? Try adding BitmapText to the gui node and rotate it along the z-axis and then tell me that the texture coordinates are set in a standard fashion. Give me a bit of time to track down where they are set… I believe it is in the individual pages, however I am not overly familiar with the class and going on memory.
I’m not sure how else to respond when I have no idea what you are talking about other than to say so. I’m not trying to be insulting but I really have no idea what you are talking about. If you stated that BitmapText was made of tiny flamingos then I might be equally confused. You’d certainly have to point out where.
…and even still, the fact that BitmapText has had a setAlpha() for over a year now also tends to invalidate the “BitmapText class from JME does not support alpha fading” comment.
I just don’t know how I’m supposed to respond to this.
I’m not sure how else to respond when I have no idea what you are talking about other than to say so. I’m not trying to be insulting but I really have no idea what you are talking about. If you stated that BitmapText was made of tiny flamingos then I might be equally confused. You’d certainly have to point out where.
…and even still, the fact that BitmapText has had a setAlpha() for over a year now also tends to invalidate the “BitmapText class from JME does not support alpha fading” comment.
I just don’t know how I’m supposed to respond to this.
This has changed then. It did NOT do this a year ago.
@t0neg0d said:
Ok... gonna try and run through the list of stuff I should have already gotten to. Starting with this!
The following code:
[java]
Effect effect = new Effect(
Effect.EffectType.FadeIn, // The type of effect to use
Effect.EffectEvent.Show, // The event that the effect is associated with
2.2f // The duration of time over which the effect executes (2.2 seconds)
);
effect.setEffectElement(someElement); // The Element to fade into the screen
screen.getEffectManager().applyEffect(effect); // Tell the effect manager to execute
[/java]
Runs an effect ONCE against the element (and child elements) you set using setEffectElement. If you are looking for an effect that happens every time an event happens, you will want to add the effect to the element itself, like so:
[java]
Element.addEffect(effect);
[/java]
This associates the effect with the defined event (specified when creating the effect) to the element the effect is being added to. Now, as for the show and showWithEffect methods. show(); bypasses the effect associated with the show event. showWithEffect shows the element using the defined effect. Hide and hideWithEffect work in a similar way. This was a user request ( @madjack ) and I’ve found it quite useful.
If i do like above, my element keeps repeating this effect
here’s my code:
[java] ressourceUpdateEffect = new Effect(Effect.EffectType.PulseColor, Effect.EffectEvent.GetFocus, .5f);
ressourceUpdateEffect.setColor(ColorRGBA.White);
ressourceUpdateEffect.setElement(ressourcePanel); // The Element to fade into the screen[/java]
@b00n said:
If i do like above, my element keeps repeating this effect
here’s my code:
[java] ressourceUpdateEffect = new Effect(Effect.EffectType.PulseColor, Effect.EffectEvent.GetFocus, .5f);
ressourceUpdateEffect.setColor(ColorRGBA.White);
ressourceUpdateEffect.setElement(ressourcePanel); // The Element to fade into the screen[/java]
@b00n said:
Hmm okay, i used that effect to display ressource changes.
Do you know how to achieve that i can recycle this effect? Do i have to use 2 effects? First to show pulse and the second to stop pulse?
Currently, yes. You would have to use two separate effects to update the state properly. Let me look into the possibility of adding to the current effect list as well. There are few additions that may be needed here anyways.