
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nate Beck - Adobeholic &#187; Console</title>
	<atom:link href="http://blog.natebeck.net/tag/console/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.natebeck.net</link>
	<description>RIA Developer, Flex / Flash, Widgets</description>
	<lastBuildDate>Wed, 21 Jul 2010 19:20:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Developing games with PushButton Engine &#8211; Using the Console</title>
		<link>http://blog.natebeck.net/2009/11/developing-games-with-pushbutton-engine-using-the-console/</link>
		<comments>http://blog.natebeck.net/2009/11/developing-games-with-pushbutton-engine-using-the-console/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 09:38:10 +0000</pubDate>
		<dc:creator>Nate Beck</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[PushButton]]></category>
		<category><![CDATA[Tip of the day]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Console]]></category>
		<category><![CDATA[PBE]]></category>

		<guid isPermaLink="false">http://blog.natebeck.net/?p=888</guid>
		<description><![CDATA[One really cool feature that we have built into the PushButton Flash Game Engine is a console. Using the Console The only thing you need to do to include the Console into your project is call PBE.startup(). package &#123; import flash.display.Sprite; import com.pblabs.engine.PBE; &#160; public class HelloConsole extends Sprite &#123; public function HelloConsole&#40;&#41; &#123; PBE.startup&#40;this&#41;;]]></description>
			<content:encoded><![CDATA[<p>One really cool feature that we have built into the <a href="http://pushbuttonengine.com/">PushButton Flash Game Engine</a> is a console.</p>
<h3>Using the Console</h3>
<p>The only thing you need to do to include the Console into your project is call PBE.startup().</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">pblabs</span>.<span style="color: #006600;">engine</span>.<span style="color: #006600;">PBE</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HelloConsole <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> HelloConsole<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			PBE.<span style="color: #006600;">startup</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Once your game is running, to access the console press the default hot key, which is the Tilde (~) / Grave (`) key. </p>
<p><a href="http://blog.natebeck.net/wp-content/uploads/2009/11/HelloConsole.png" target="_blank"><img src="http://blog.natebeck.net/wp-content/uploads/2009/11/HelloConsole-300x229.png" alt="HelloConsole" title="HelloConsole" width="300" height="229" class="alignnone size-medium wp-image-899" /></a></p>
<p>As of this post, the latest revision of the <a href="http://www.pushbuttonengine.com">PushButton Engine</a> is revision 702.  In this version there are some commands registered by default:</p>
<ul>
<li><b>help</b> &#8211; List known commands.</li>
<li><b>clear</b> &#8211; Clears the console history.</li>
<li><b>listDisplayObjects</b> &#8211; Outputs the display list.</li>
<li><b>showFps</b> &#8211; Show an FPS/Memory usage indicator.</li>
<li><b>verbose</b> &#8211; Set verbosity level of console output.</li>
<li><b>version</b> &#8211; Echo PushButton Engine version information.</li>
</ul>
<h3>Quick Tricks</h3>
<p>The console supports a few shortcuts to make your life easier:</p>
<ul>
<li>The console is not case-sensitive, so don&#8217;t worry if you put showFps or shOwFPS, the same command will execute.</li>
<li>You can use the up and down arrows to move through your command history.</li>
<li>By pressing enter on an empty command line, you can add new lines.  This is helpful for adding space between commands to make it easier to read.</li>
<li>You can use the &#8220;name&#8221; property on a DisplayObject to make meaningful names show up in the listDisplayObjects command.</li>
<li>Different Log Levels are colored by default, to change the colors edit com.pblabs.engine.debug.LogColor.</li>
</ul>
<h3>Creating custom commands for the console</h3>
<p>The PBE console also supports the ability for the developer to add their own commands.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">pblabs</span>.<span style="color: #006600;">engine</span>.<span style="color: #006600;">PBE</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">pblabs</span>.<span style="color: #006600;">engine</span>.<span style="color: #006600;">debug</span>.<span style="color: #006600;">Console</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">pblabs</span>.<span style="color: #006600;">engine</span>.<span style="color: #006600;">debug</span>.<span style="color: #006600;">Logger</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConsoleCommand <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ConsoleCommand<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			PBE.<span style="color: #006600;">startup</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
			Console.<span style="color: #006600;">registerCommand</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;test&quot;</span>, onTestCommand, <span style="color: #ff0000;">&quot;This is a test command.&quot;</span><span style="color: #66cc66;">&#41;</span>;
			Console.<span style="color: #006600;">registerCommand</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;testStrict&quot;</span>, onTestStrict, <span style="color: #ff0000;">&quot;Test strict parameters.&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> onTestCommand<span style="color: #66cc66;">&#40;</span>... <span style="color: #006600;">args</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			Logger.<span style="color: #0066CC;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #ff0000;">&quot;onTestCommand: &quot;</span>+args<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> onTestStrict<span style="color: #66cc66;">&#40;</span>str:<span style="color: #0066CC;">String</span>, num:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			Logger.<span style="color: #0066CC;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #ff0000;">&quot;You passed in the string: &quot;</span>+str<span style="color: #66cc66;">&#41;</span>;
			Logger.<span style="color: #0066CC;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #ff0000;">&quot;You passed in the number: &quot;</span>+num<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Parameters are passed in sequence using spaces.  So to run the test command, I would open the console, and then type &#8220;test a b c 1 2 3&#8243;.  This would then call the onTestCommand method and pass in an array with 6 elements.</p>
<p>Below is an example of what using custom commands in the console looks like.</p>
<p><a href="http://blog.natebeck.net/wp-content/uploads/2009/11/ConsoleCommand.png"><img src="http://blog.natebeck.net/wp-content/uploads/2009/11/ConsoleCommand-300x229.png" alt="ConsoleCommand" title="ConsoleCommand" width="300" height="229" class="alignnone size-medium wp-image-895" /></a></p>
<h3>Changing the Console HotKey</h3>
<p>Some of our good friends over in the Netherlands use different keyboard layouts, so they requested the ability to change the hot key binding to another key.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">pblabs</span>.<span style="color: #006600;">engine</span>.<span style="color: #006600;">PBE</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">pblabs</span>.<span style="color: #006600;">engine</span>.<span style="color: #006600;">core</span>.<span style="color: #006600;">InputKey</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">pblabs</span>.<span style="color: #006600;">engine</span>.<span style="color: #006600;">debug</span>.<span style="color: #006600;">Console</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">pblabs</span>.<span style="color: #006600;">engine</span>.<span style="color: #006600;">debug</span>.<span style="color: #006600;">Logger</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">pblabs</span>.<span style="color: #006600;">engine</span>.<span style="color: #006600;">debug</span>.<span style="color: #006600;">UIAppender</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">StageAlign</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">StageScaleMode</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestConsole <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> TestConsole<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			PBE.<span style="color: #006600;">startup</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			UIAppender.<span style="color: #006600;">hotKey</span> = InputKey.<span style="color: #006600;">C</span>.<span style="color: #006600;">keyCode</span>;
			Console.<span style="color: #006600;">registerCommand</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;test&quot;</span>, onTestCommand, <span style="color: #ff0000;">&quot;My test command&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> onTestCommand<span style="color: #66cc66;">&#40;</span>... <span style="color: #006600;">args</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			Logger.<span style="color: #0066CC;">print</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #ff0000;">&quot;onTestCommand: &quot;</span>+args<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><font color="#FF0000"><b>WARNING!!!</b></font> When changing the hot key to another key, the input textfield doesn&#8217;t escape the new key binding.  So you must remove focus from the input field to use the hot key to close the console.</p>
<p>More information on this can be found in <a href="http://code.google.com/p/pushbuttonengine/issues/detail?id=98">issue 98</a>.</p>
<h3>What&#8217;s coming?</h3>
<p>I do have plans on adding either tab-complete or a drop-down auto complete list into the console which will match avaliable commands.</p>
<p>Another thing that I&#8217;m currently working on is code-named Tumbler.  It&#8217;s and Adobe AIR version of the console which has additional features to assist in debugging and troubleshooting your games.  </p>
<p>It&#8217;s a proof-of-concept at the moment&#8230; but if there is enough interest in it&#8230; I may spend more time on it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.natebeck.net/2009/11/developing-games-with-pushbutton-engine-using-the-console/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
