Entitymodifiers runs but show no change

Go To StackoverFlow.com

0

I'm making a board game and I'm stuck on problem that's been killing 3-4 hours for me now. No docs anywhere so I'm just doing guesswork without luck.

Consider this:

public void highlightBlockTest(BoardCoordinate bc) {
  Log.i("highlightBlock()", "entered.");

  Point p = new Point(bc.getPuzzlePiece().getDestination());
  Rect rect = getBoardCoordinateRectFromPoint(p);

  int x = rect.getX();
  int y = rect.getY();
  int w = rect.getWidth();
  int h = rect.getHeight();

  Entity e = new Entity(0, 0);
  Rectangle r;

  r = new Rectangle(x, y, w, 5);
  e.attachChild(r);
  r = new Rectangle(x, y, 5, h);
  e.attachChild(r);
  r = new Rectangle(x + w - 5, y, 5, h);
  e.attachChild(r);
  r = new Rectangle(x, y + h - 5, w, 5);
  e.attachChild(r);

  SequenceEntityModifier sem = new SequenceEntityModifier(
      new DelayModifier(1f),
      new AlphaModifier(1f, 0.0f, 1.0f, new IEntityModifierListener() {
        @Override
        public void onModifierStarted(IModifier<IEntity> arg0, IEntity arg1) {
          System.out.println("Alpha start!");
        }

        @Override
        public void onModifierFinished(IModifier<IEntity> arg0, IEntity arg1) {
          System.out.println("Alpha stop!");
        }
      })
  ); 

  e.registerEntityModifier(sem);
  this.mScene.attachChild(e);

  return;
}

This code is supposed to draw a "highlight" rectangle for a particular block. The rectangle draws all right, but the AlphaModifier does not applicate its values on the entity in question. The DelayModifier works just fine.

I added ModifierListener just to see if it gets called, and it does; I see "Alpha start" and "Alpha stop" in Logcat. But the highlighted rectangle is still there, clearly visible on the board.

As a last resort I added a MoveModifier as well to move the rectangle 50 pixels to the right during 5 seconds, and the rectangle was moved off screen instantaneous.

Why aren't these modifiers working as expected?

2012-04-03 19:46
by bos


0

You need to set the blend function, call .setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); on the entities.

2012-04-04 11:09
by JohnEye
Still not working :/ It is working if I do for (int n = 0; n < e.getChildCount(); n++) { e.getChild(n).registerEntityModifier(sem); }, i.e. apply the Modifier to all subchildren. But according to the AndEngine book by Rick Rogers this should not be needed, since applying a Modifier on an entity parent will apply the same modifier to the children as well. However, when I apply anything on the parent nothing happens to the children - bos 2012-04-04 11:30
If I only do one rectangle and attach that one to the scene (instead of the entity and then the entity to the scene), all works perfectly. So it seems that the Modifier won't apply to children.

If there only were any docs telling me this before I wasted 10+ hours - bos 2012-04-04 11:35

So you solved the problem - JohnEye 2012-04-05 09:38
Well, yes and no. Yes, it's solved if I use only one rectangle and don't nest rectangles into an Entity. No, it's not solved since I want a rectangle with a "hole" in it and I can only get it to work with one rectangle. Perhaps I will have to make a bitmap-sprite of it - bos 2012-04-05 10:55
Have you tried using Entity.callOnChildren(IEntityCallable pEntityCallable)? You can also iterate over the entity manually using getChildCount() and getChild(int pIndex). Or is there a reason you cannot do neither of these - JohnEye 2012-04-05 11:05
Ads