Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndEngine. Execute a sequence on collision

I wanna in andEngine execute a sequence (sprite animation) when sprite collides with something. Tryed to define the sequenceEntityModifier in the IUpdateHandler but the sequence doesn't execute.

Any suggestion about how to achive this ? Where to put my animation code ?

sprite.registerUpdateHandler(new IUpdateHandler() {
    @Override
    public void onUpdate(float pSecondsElapsed) {
        if(sprite.collidesWith(shape)) {


            // this will not work
            final SequenceEntityModifier enemyModifier = new SequenceEntityModifier(
            ...
            )
            // this too
            sprite.setScale(0.5f);

        }
    }
    @Override
    public void reset() {
    }
});
like image 528
Claudio Ferraro Avatar asked Sep 23 '26 19:09

Claudio Ferraro


1 Answers

I guess you are not using Box2D, so register this IUpdateHandler to your sprite:

sprite.registerUpdateHandler(new IUpdateHandler() {
    @Override
    public void onUpdate(float pSecondsElapsed) {
        if(sprite.collidesWith(shape)) {
            //animation here
        }
    }

    @Override
    public void reset() {
    }
});
like image 69
Jong Avatar answered Sep 26 '26 08:09

Jong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!