2
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Doh! I should have looked at the super. in onModifierFinished to figure it out, lol thank you!! \$\endgroup\$
    – SSH This
    Commented Dec 12, 2012 at 23:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .