0

I'm trying to change alpha value of a HUD, but it is not changing. I've tried with AlphaModifier and changing with method .setAlpha(), but with no result. As i can see, a HUD entity does not have setBlendingFunction() method.

This is what i am now trying to do:

this.mHud = new HUD() {
        @Override
        protected void onManagedUpdate(float pSecondsElapsed) {
            super.onManagedUpdate(pSecondsElapsed);
            if(flag) {
                while (this.getAlpha() > 0) {
                    this.set(this.getAlpha() - (pSecondsElapsed / 1.5f));
                }
            } else {
                while (this.getAlpha() < 1) {
                    this.setAlpha(this.getAlpha() + (pSecondsElapsed / 1.5f));
                }
            }
        }
    };

The "flag" variable is initialized to false, and it is changed when a button is pressed.

I have tried this too:

 private static final IEntitiyModifier mToTransparentModifier = new AlphaModifier(1, 1, 0);
private static final IEntitiyModifier mToOpaqueModifier = new AlphaModifier(1, 0, 1);
this.mToTransparentModifier.setAutoUnregisterWhenFinished(true);
this.mToOpaqueModifier.setAutoUnregisterWhenFinished(true);

if(flag) {
    this.mHud.registerEntityModifier(this.mToTransparentModifier);
}else {
    this.mHud.registerEntityModifier(this.mToOpaqueModifier);
}

Any help would be appreciated. Thanks

GmloMalo
  • 667
  • 7
  • 14
  • 1
    Have you added any child sprite with a texture to the HUD? HUD is only transparent entity. – Derek K Oct 17 '15 at 16:10
  • @DerekK I 've just realized for that yesterday, but now i'm trying to change the Alpha value for sprites, using the second code, but it only works once: once for the Transparent modifier, and once for the Opaque modifier. Then it do nothing, despite unregistering modifiers on sprites. Any idea? Thanks for the answer! – GmloMalo Oct 17 '15 at 16:32
  • Don't unregister modifiers. If you want to change modifier continuously, you must call reset() in overriden onModifierFinished() method in Modifier class. – Derek K Oct 17 '15 at 17:49
  • @DerekK This is not working as I spected since i want only entityModifiers to work when pressing a button. When i press button A, transparent modifier should works, and when press button B, opaque modifier should start. I have tried to reset modifiers when A or B button is pressed, controled by a flag to control if is first time to register modifier, or second or more time to reset it since is already registered. But it reset both registered modifiers with the only method entity.resetEntityModifiers(); – GmloMalo Oct 17 '15 at 18:26

0 Answers0