Simple Nifty Java Effect Example

Hi!

Sorry, I din’t find an answer to my easy question, and I didn’t find any tutorials about that. I generate a dynamic Inventory screen by java which works quite well, but now I want to add some effects to my new Panels/etc., but I didn’t find any working solution for doing that. My Code so far:
[java]
Element thisElement=screen.findElementByName(“itemField_inner#”+1);
ColorPulsate pulsateEffect = new ColorPulsate();
Properties properties = new Properties();
properties.put( “startColor” , “#f418” );
properties.put( “endColor” , “#f638” );
properties.put( “pulsateType” , “sin” );
properties.put( “period” , “2500” );
properties.put( “cycle” , “false” );
EffectProperties prop = new EffectProperties(properties);
pulsateEffect.activate( nifty, thisElement, prop );
pulsateEffect.execute(thisElement, 1, new Falloff(), nifty.getRenderEngine());

       Effect effect = new Effect( nifty, false, false, false, "", "", "", true, EffectEventId.onStartHover);
       effect.init( thisElement, pulsateEffect, prop, new TimeProvider(), new LinkedList() );
       thisElement.registerEffect(EffectEventId.onStartHover, effect);    
       effect.enableInfinite();[/java] 

Could anyone give me a simple working example of how I could add this effect? Thank you very much!

How are you creating the panels? Using either an XML or a builder its very easy to add custom effects and then trigger them as required…

I think you are going a hard way about it here…

Make sure your element is flagged as “visible to mouse”. I once had a similar issue with onHover events, because Nifty did not automatically set elements to visibleToMouse when the effect was added for them.

I need a dynamic amount of fields, that are created by java. “visible to mouse” is already set. Could anyone post a small working example? Maybe I can reproduce it :slight_smile:

EDIT: I also thought of creating it by xml, but then I’d have to remove the unnecessary effects…

Use builders to create them dynamically from java - read the nifty bible, it covers using builders.