<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>how to animate properly</title>
		<link>http://www.allegro.cc/forums/view/590031</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 13 Feb 2007 19:22:08 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi,<br />    my game&#39;s coming along nicely but I&#39;ve need to learn how to animate properly.<br />At the moment the way it works is :-</p><div class="source-code snippet"><div class="inner"><pre>
  <span class="k1">if</span><span class="k2">(</span>ball_moving<span class="k2">)</span> draw_ball<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
  <span class="k1">if</span><span class="k2">(</span>fan_turning<span class="k2">)</span> draw_fan<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
  <span class="k1">if</span><span class="k2">(</span>player_moving<span class="k2">)</span> draw_player<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

 In the draw_player() function there&#39;s a rest(10) call, so at the moment if the player is moving there&#39;s a rest(10) between every loop but if he&#39;s not the draw_ball() and draw_fan() get called quickly. I need to make so things are more consistent.<br /> A bit of help would be greatly appreiciated.</p><p>Will
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Mon, 12 Feb 2007 18:53:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Animation is not done at all in the way you describe. The appropriate approach is to do a balanced game loop like this:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> int_proc<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
    <span class="k3">+</span><span class="k3">+</span>timer<span class="k2">;</span>
<span class="k2">}</span>

<a href="http://www.allegro.cc/manual/install_int" target="_blank"><span class="a">install_int</span></a><span class="k2">(</span>proc, FPS<span class="k2">(</span><span class="n">60</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="k1">while</span> <span class="k2">(</span>game<span class="k2">)</span> <span class="k2">{</span>
    <span class="k1">while</span> <span class="k2">(</span>timer<span class="k2">)</span> <span class="k2">{</span>
        game_logic<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
        animate_stuff<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
        <span class="k3">-</span><span class="k3">-</span>timer<span class="k2">;</span>
    <span class="k2">}</span>
    draw_stuff<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

And then draw things in &#39;draw_stuff&#39; and animate things in &#39;animate_stuff&#39;.</p><p>Animating is easy. For example, if you have a bitmap animation, all you need is an array of bitmaps and an index into the array: by increasing the index, your game object will be drawn differently each time it is drawn, i.e. be animated.</p><p>Animation is all about altering the drawing parameters of a game object.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Mon, 12 Feb 2007 20:48:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks axilmar.</p><p> I think that should be </p><p>install_int(int_proc, FPS(60)); but I get what you mean.</p><p> I&#39;ll give this a go but I don&#39;t really understand what this code does.</p><p> Is this right ? - While draw_stuff() is doing it&#39;s thing the timer integer gets<br />increased. Then when execution gets back to the animate_stuff function it calls those functions decrementing timer each time until it&#39;s back to 0. Then draws again.<br /> So the longer it takes to draw the more times the logic gets updated ?</p><p> Is that right ? Wouldn&#39;t this cause a lot of jumpy sprite drawing ?</p><p>Thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Mon, 12 Feb 2007 20:59:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It might cause some jumping in slower computers, but generally it is one of the most used ways to code a game loop.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Tue, 13 Feb 2007 17:57:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p> Right.<br /> It seems this necessitates doing all the non-drawing stuff all at once and then all the drawing all at once. This isn&#39;t how my game works but I should be able to adapt it into this way.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Tue, 13 Feb 2007 19:22:08 +0000</pubDate>
	</item>
</rss>
