Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to get a "highlighter" circle to follow around a sprite, but I am having trouble, I thought I could use the onUpdate method that's available to me in SequenceEntityModifier but it's not working for me. Here is my code:

    // make sequence mod with move modifier
    SequenceEntityModifier modifier = new SequenceEntityModifier(myMovemod) {

        @Override
        protected void onModifierFinished(IEntity pItem) {
            // animation finished
            super.onModifierFinished(pItem);
        }

        public float onUpdate(float pSecondsElapsed, IEntity pItem) {

            highlighter.setPosition(player2.getX() - highlighterOffset, player2.getY() - highlighterOffset);
            return pSecondsElapsed;
        } 

    };

When onUpdate is completely commented out, the sprite moves like I want it to, everything is ok. When I put the onUpdate in, the sprite doesn't move at all. I have a feeling that I am overriding the original onUpdate's actions?

Am I going about this the wrong way? I am new to Java, so please feel free to advise if this isn't going to work.

UPDATE: The player2 is the sprite that I'm trying to get the highlighter to follow.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

I think you're right - you are overriding SequenceEntityModfier's onUpdate method. Simply call parent's onUpdate method when you are overriding it:

@Override
public float onUpdate(float pSecondsElapsed, IEntity pItem) {
    highlighter.setPosition(player2.getX() - highlighterOffset, player2.getY() - highlighterOffset);
    return super.onUpdate(pSecondsElapsed, pItem);
}

Also, it's a good idea to use the @Override annotation whenever applicable, because that way you'll know if you are overriding a method or not.

share|improve this answer
    
Doh! I should have looked at the super. in onModifierFinished to figure it out, lol thank you!! –  SSH This Dec 12 '12 at 23:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.