Bugfix for looping an animation

Animation would not stop after loopcount since it is updated after the
check, it would stop after loopcount +1