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 want to animate my player from bigger size to smaller size and then smaller size to bigger size continuously. We can use setScale() method to re-size any sprite but is there any way to animate with it?

And one more thing, if I scale any sprite after creating it's physics body, the sprite is visually scaled but the physics body does not scaled.

So is there any optimum solution to animate the physics body from bigger to smaller and then smaller to bigger?

share|improve this question
1  
I don't understand the problem. Why not scale both the physics body and the sprite? –  Anko Mar 7 '13 at 12:00
    
You want to look into linear interpolation. –  Vaughan Hilts Mar 7 '13 at 14:39

2 Answers 2

up vote 3 down vote accepted

You have to use entity modifier for this purpose.

For example,

sprite.registerEntityModifier(new LoopEntityModifier(new SequenceEntityModifier(new ScaleModifier(1,1,1.5),new ScaleModifier(1,1.5,1))));

Above code can become useful to you. If you found any mistake then please make it correct because I don't check it.

And now turn for body, as per my suggestion you have to create different body each time to show scale up and down. You can write this code in managerUpdate method. One thing also you can check that change fixturedef of the body and try to create new body in that way also. Whatever choice you like.

share|improve this answer
    
Thank you, It works perfectly :) –  prium Mar 7 '13 at 20:47

sprite.registerEntityModifier(new LoopEntityModifier(new SequenceEntityModifier(new ScaleModifier(1,1,(float)1.5),new ScaleModifier(1,(float)1.5,1))));

share|improve this answer
2  
Please explain what this code is doing; it's not very obvious –  congusbongus Aug 28 '13 at 11:03

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.