Scene AlphaModifier?

  ... discussions about development with the GLES2 branch of AndEngine.

Scene AlphaModifier?

Postby ChrisB2404 » Tue Feb 14, 2012 3:59 pm

Hi,

I am trying to make the entire scene fade out however Scene does not allow for .setBlenFunction. I know that I am attaching a Sprite to the scene and therefore the blend should apply to all children of the scene but the spirtes do not fade.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. final Scene scene = new Scene();
  2.                 scene.setBackground(new ColorBackground(0.0f, 0.0f, 0.0f));            
  3.                 TextureRegion aRegion= this.introLibrary.get(IntroXML.R);
  4.                
  5.                 /* Create the face and add it to the scene. */
  6.                 final Sprite aSprite = new Sprite(66, 491, aRegion);
  7.                 aSprite.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
  8.                 scene.registerEntityModifier(new AlphaModifier(3f, 0f, 1f));
  9.                 scene.attachChild(aSprite);
  10.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


My understanding from the above should mean that all sprites attached to the scene would have their alpha values increment from 0 to 1. This does work if I use the alphaModifier on the sprite however if I had 50 in the scene then that is no going to be a smart idea.

Why does this modifier not work for the sprites?

Note: Other modifiers do work for the scene

Thanks
User avatar
ChrisB2404
 
Posts: 80
Joined: Sat Feb 04, 2012 10:39 pm
Location: Dundee

Re: Scene AlphaModifier?

Postby jaym » Tue Feb 14, 2012 10:39 pm

The alpha values of the parent entities are not inherited by children. It will not work by setting the parents alpha to 0, or 1 or any other value.

One way I suppose you can achieve this without much thought is to simply create a rectangle to overlap the scene with a color of black and register the alpha modifier to that. Large rectangles can take some performance on older phones though so it might even be best to create a hud layer and attach the black rectangle there if your scene is bigger than your camera area. Also don't forget to detach the rectangle anytime it's alpha is set to 0 (invisible rectangles with culling still cost performance).
AndEngine for Android Game Development Cookbook - Based on AndEngine's latest, greatest, GLES2.0 AnchorCenter branch!
jaym
 
Posts: 690
Joined: Wed May 04, 2011 10:08 pm


Return to GLES2

Who is online

Users browsing this forum: Google [Bot], Therdiday, vantusmantus and 26 guests