Decreasing One Variable as Another Increases
<p>I am putting together a small game in Java, one of the problems I have encountered is increasing the speed of the animation as the player character's movement speed increases.</p>

<p>To increase the speed of animation, the time each frame of the animation is displayed must be decreased, from a maximum of '0.2' for the slowest speed and '0.1' for the highest speed.</p>

<p>My current code works, but it is quite clearly a little clumsy. Unfortunately, I can't think of an elegant solution to replace it.</p>

<pre><code>public float getAnimationSpeed()
{
    float _absVel = Math.abs(_vel.x);

    if(_absVel &gt; 10 &amp;&amp; _absVel &lt;= 50)
    {
        return 0.1f;
    }
    else if(_absVel &gt; 50 &amp;&amp; _absVel &lt;= 150)
    {
        return 0.075f;
    }
    else if(_absVel &gt; 150)
    {
        return 0.05f;
    }
    else
    {
        return 0f;
    }
}
</code></pre>

<p>You might notice the function may also return a zero, which is used to display the animation as still(For example, when the player character has a velocity of 0, the animation shouldn't be playing).</p>