Andengine fade in/out and alpha modifiers not working
Asked Answered
U

2

12

I have a problem with AndEngine GLES2.

I have this code:

Sprite black = new Sprite(0,0, blackRegion, this.getVertexBufferObjectManager());
black.setSize(CAMERA_WIDTH, CAMERA_HEIGHT);

black.registerEntityModifier(new AlphaModifier(2, 0, 255));

mScene.attachChild(black);

So it's not working. Nothing does...

What do I need to do?

Undergrowth answered 11/3, 2012 at 15:35 Comment(0)
A
22

Did you set the blend function properly? Example:

sprite.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
Anhanhalt answered 12/3, 2012 at 0:27 Comment(0)
A
4

I tried the above but it's not working for me as it should. The modifier works but instead of a steady fade out the image fades out a number of times for the mentioned duration. Any ideas?

Well ultimately i figured out what i was doing wrong. Here's it...

        anySprite.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    IEntityModifier iem = new AlphaModifier(seconds, 0, 255); //for some unknown reason i was passing invalid values and hence it didn't work then :)
    iem.setRemoveWhenFinished(true);
    anySprite.registerEntityModifier(iem);
Accelerometer answered 16/3, 2012 at 13:54 Comment(2)
Yeah me too... What do we need to do?Undergrowth
The reason you are fading out multiple times is because the AlphaModifier goes from a scale of 0.0f to 1.0f instead of 0 to 255. where 1.0f is 255 on a regular color wheel.Kaiulani

© 2022 - 2024 — McMap. All rights reserved.