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?
You need to set the blend function, call .setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
on the entities.
If there only were any docs telling me this before I wasted 10+ hours - bos 2012-04-04 11:35
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