Dynamically adding Effects

I am trying to add effects at runtime and I thought that this would work…

[java]element.registerEffect(eventID, new Shake());[/java] Shake is not a Effect? Its a EffectImpl. I understand this but I could create a EffectBuilder but EffectBuilder has no build method that returns a Effect… so how would you use the element.registerEffect(EffectEventId, Effect) method?



I did look through the nifty bible to no avail… but that has not faltered thy faith in goo-e-y beliefs.

Unfortunatly some (actually a lot :/) of the public APIs are not supposed to be called by the user but internally by other parts of Nifty. This is actually pretty bad since you don’t know what you can call and what not. This was one reason why the standard controls got their own package and set of interfaces that clearly defines the control API. In other parts of Nifty, like in many of the core classes, the situation is still pretty bad. This is something we need to address in the future.



The short answer to your question is:

You can’t EASILY dynamically add “only” effects to an element. You can dynamically add effects only together with a new element. I would suggest you add effects when you create the elements (in XML or with the Builders).



The long answer is:

If you really really really need to add effects dynamically there might be a way doing it that involves messing with the EffectType classes but I don’t think this has been done before. You can look at the way Nifty does that internally - it calls the registerEffect() method you’ve mentioned somewhere - and use a similar way for your purpose but I wouldn’t recommend it :slight_smile:



PS: Maybe someone else already did add only effects to an element and can share a code snippet? I don’t think I’ve needed that feature somewhere tho.

I’m probably going to have to do some workaround hack to get it to work thanks for your input. If I get it done I’ll post my results or my frustration here.