0

I have to implement a cooldown animation on a chess board with libgdx. You can see an example on the following video: cooldown colour is yellow. A Figure has a cooldown time after each movement. Should I use processbar or libgdx animation

click

I have absolut no idea how to do it and with which source of libgdx I can do it. I hope someone can help me.

  • Just draw a sprite (even a 1x1 `Pixmap` with a yellow pixel would be enough) with over time decreasing size. – noone Aug 04 '14 at 11:57

1 Answers1

0

Okay, think about it like this: after the unit moves to a square block, you initiate a timer for that square block (or for the unit, and based on the unit's position you do the animation for the block. Either works.)

The timer goes from 1...0 (if you want it to be 500 ms, then it would go from 0.5 to 0, but at the multiplication you will normalize it up to 1 to 0 by multiplying it with 1 / 0.5 which is 2).

When you draw out the block, then if the timer is > 0, then you draw out a rectangle using a ShapeRenderer that begins at the bottom corner, up to height_of_block * timer (that goes from 1 to 0). If your drawing order is background of square block -> yellow rectangle -> unit on top of square block, then you will have the animation as you update the animation by time.

To track time, use the following I wrote down here: How to track time in Libgdx(android)

Community
  • 1
  • 1
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
  • That means, I need to use Animataion to do this task? I have to make group of pictures which animate filling a rectangle? – user3741505 Aug 04 '14 at 15:59
  • you don't need Animation class. You basically just need a timer that runs from some time to zero, and you scale this to the [1...0] interval, and use this as a factor for the height of the rectangle you're drawing out. – EpicPandaForce Aug 04 '14 at 18:22
  • what is the time 0.125f from our track time? – user3741505 Aug 04 '14 at 23:04
  • It's the maximum possible interval for the simulation of time. This is so that if there is a freeze then the render() call might be called too late and if that happens then you can have time skips, and this way removes it. Basically 0.125f is a constant EPSILON value. – EpicPandaForce Aug 05 '14 at 08:19