Search code examples
androidandenginealphablendingalpha-transparency

Change Sprite alpha previously changed by AlphaModifiers


I'm running AlphaModifier on a Sprite

mSprite.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
mSprite.registerEntityModifier(new AlphaModifier(.5f,1,0.4f));

After that i want to cahnge alpha of mSprite to 1 again.
i tried :

mSprite.setAlpha(1f); 

It won't work

How can i set that alpha to 1 again?


Solution

  • First of all, if you want to bring the behaviour back from before you modified it, you should probably call

    setBlendFunction(IShape.BLENDFUNCTION_SOURCE_DEFAULT, IShape.BLENDFUNCTION_DESTINATION_DEFAULT)

    otherwise before each rendering call it will use your parameters. In addition, since the AlphaModifier will be called at each onUpdate() (this means at least one per frame), it will overwrite your new value. You should remove the modifier (or make sure that it is removed once it finishes), and then you can set the transparency you prefer.