<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Lag when holding down key.</title>
		<link>http://www.allegro.cc/forums/view/618449</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 02 Jul 2021 18:22:08 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello, I&#39;m relatively new to programming and this is my first &quot;game&quot;.<br />I had to program a Mario game for an assignment. <br />the little game there is so far works fine, the only problem is that when I hold down a key, any key, even one that I haven&#39;t programmed an event for, the whole game start to slow down.</p><p>this is the github repo: <a href="https://github">https://github</a> (dot) com/RoccoGas/Mario_progra/blob/master/Mario_progra</p><p>I suppose the problem is somewhere in the &quot;level.c&quot; file, in the way that I structured the game loop, but I really have no idea.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gestaldi)</author>
		<pubDate>Wed, 30 Jun 2021 22:45:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Not an expert, but is al_install_keyboard not necessary?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Wed, 30 Jun 2021 23:10:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@DanielH I install everything in  an &quot;initialize_allegro()&quot; function that is called as soon as main starts. The declarataion of the function s in &quot;allegro.c&quot;. al_install_keyboard() is in there.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gestaldi)</author>
		<pubDate>Wed, 30 Jun 2021 23:18:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Not sure exactly what the problem is. But try emptying the event queue before redrawing, and see if that helps:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">case</span> ALLEGRO_EVENT_TIMER:
    update_mario<span class="k2">(</span><span class="k3">&amp;</span>mario, keyboardState<span class="k2">)</span><span class="k2">;</span>
    redraw <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
    <span class="k1">break</span><span class="k2">;</span>
</pre></div></div><p>

And later you do:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>redraw <span class="k3">&amp;</span><span class="k3">&amp;</span> <a href="http://www.allegro.cc/manual/al_is_event_queue_empty"><span class="a">al_is_event_queue_empty</span></a><span class="k2">(</span>queue<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
    draw_world<span class="k2">(</span>camera, map, tiles<span class="k2">)</span><span class="k2">;</span>
    draw_mario<span class="k2">(</span>mario<span class="k2">)</span><span class="k2">;</span>
    <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
    redraw <span class="k3">=</span> <span class="k1">false</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

You could also call <span class="source-code"><a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a></span> instead of <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_next_event"><span class="a">al_get_next_event</span></a></span> to avoid running the loop when there is nothing to do.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Wed, 30 Jun 2021 23:48:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@torhu Yah that worked lmao, thanks everybody for the help. Thank God forums like these are still alive. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gestaldi)</author>
		<pubDate>Thu, 01 Jul 2021 00:00:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You were probably being spammed with repeating ALLEGRO_EVENT_KEY_CHAR events.</p><p>By ignoring the unused events, the event queue then flowed smoothly again.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 02 Jul 2021 18:22:08 +0000</pubDate>
	</item>
</rss>
