<?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>Enigmatic Thought &#187; pushbutton engine</title>
	<atom:link href="http://blog.enigmaticthought.com/tag/pushbutton-engine/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.enigmaticthought.com</link>
	<description>import com.enigmaticThought.blog;</description>
	<lastBuildDate>Fri, 25 Jun 2010 19:54:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Adding pushbutton engine entities via code</title>
		<link>http://blog.enigmaticthought.com/2009/04/adding-pushbutton-engine-entities-via-code/</link>
		<comments>http://blog.enigmaticthought.com/2009/04/adding-pushbutton-engine-entities-via-code/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 22:47:24 +0000</pubDate>
		<dc:creator>Matt C</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[pushbutton]]></category>
		<category><![CDATA[pushbutton engine]]></category>
		<guid isPermaLink="false">http://enigmaticthought.com/?p=66</guid>
		<description><![CDATA[I have just started using the pushbutton engine which went into public beta recently. It&#8217;s a flex/flash game engine that is designed around modularity between entities so that you can share code. Unfortunately, their documentation is rather sparse and can be hard to find. The best reference, the API documentation is very difficult to get [...]]]></description>
			<content:encoded><![CDATA[<p>I have just started using the <a href="http://pushbuttonengine.com/">pushbutton engine</a> which went into public beta recently.  It&#8217;s a flex/flash game engine that is designed around modularity between entities so that you can share code.  Unfortunately, their documentation is rather sparse and can be hard to find.  The best reference, <a href="http://pushbuttonengine.googlecode.com/svn/site/APIDocs/index.html">the API documentation</a> is very difficult to get to since it&#8217;s hosted in their <a href="http://code.google.com/p/pushbuttonengine/">google code project</a> and not directly linked to on their website.</p>
<p>Everything they give you is set up for a single player experience that is built around xml files describing the components and their entities.  So what if you want to dynamically load information?  I did a lot or tracing and here is how I loaded a tile map that I would be able to dynamically create on the server and pass to client as xml.  FYI I&#8217;m using the <a href="http://lostgarden.com/2007/05/dancs-miraculously-flexible-game.html">Lost Garden PlanetCute</a> tiles since they&#8217;re not only Creative Commons, but really good looking.</p>
<p>Since I&#8217;m going to already have all the graphics embedded on the client, I can use the xml loader that the pushbutton documentation uses.  I also included my Simple Spatial Manager and Scene components, which handle the placement and drawing, respectively.</p>
<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.enigmaticthought.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=66&amp;download=Sprites.xml">Sprites.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6611"><td class="code" id="p66code11"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;things</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SimpleSpatial&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;PBLabs.Rendering2D.BasicSpatialManager2D&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Manager&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Scene&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;PBLabs.Rendering2D.Scene2DComponent&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Scene&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SpatialDatabase</span> <span style="color: #000066;">componentReference</span>=<span style="color: #ff0000;">&quot;SimpleSpatial&quot;</span> <span style="color: #000066;">componentName</span>=<span style="color: #ff0000;">&quot;Manager&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SceneViewName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MainView<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SceneViewName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Position<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;x<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/x<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;y<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/y<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Position<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RenderMask</span> <span style="color: #000066;">childType</span>=<span style="color: #ff0000;">&quot;String&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;_0<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Renderable<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/_0<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/RenderMask<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;brown&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;PBLabs.Rendering2D.SpriteSheetComponent&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SpriteSheet&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">filename</span>=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Brown Block.png&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dirt&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;PBLabs.Rendering2D.SpriteSheetComponent&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SpriteSheet&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">filename</span>=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Dirt Block.png&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;grass&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;PBLabs.Rendering2D.SpriteSheetComponent&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SpriteSheet&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">filename</span>=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Grass Block.png&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;plain&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;PBLabs.Rendering2D.SpriteSheetComponent&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SpriteSheet&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">filename</span>=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Plain Block.png&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;stone&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;PBLabs.Rendering2D.SpriteSheetComponent&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SpriteSheet&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">filename</span>=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Stone Block.png&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;water&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;PBLabs.Rendering2D.SpriteSheetComponent&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SpriteSheet&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">filename</span>=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Water Block.png&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wood&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;PBLabs.Rendering2D.SpriteSheetComponent&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SpriteSheet&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">filename</span>=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Wood Block.png&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;group</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SpriteData&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;objectReference</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SimpleSpatial&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;objectReference</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Scene&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;objectReference</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;brown&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;objectReference</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dirt&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;objectReference</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;grass&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;objectReference</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;plain&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;objectReference</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;stone&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;objectReference</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;water&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;objectReference</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wood&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/group<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/things<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>
<p>And I embed the images in the swf, again, following the documentation</p>
<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.enigmaticthought.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=66&amp;download=LevelTiles.as">LevelTiles.as</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6612"><td class="code" id="p66code12"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">enigmatic</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> PBLabs.<span style="color: #006600;">Engine</span>.<span style="color: #006600;">Resource</span>.<span style="color: #006600;">ResourceManager</span>;
	<span style="color: #0066CC;">import</span> PBLabs.<span style="color: #006600;">Rendering2D</span>.<span style="color: #006600;">ImageResource</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LevelTiles
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//Embeds</span>
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Brown Block.png&quot;</span>, mimeType=<span style="color: #ff0000;">'application/octet-stream'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _brownBlock:<span style="color: #000000; font-weight: bold;">Class</span>;
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Dirt Block.png&quot;</span>, mimeType=<span style="color: #ff0000;">'application/octet-stream'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _dirtBlock:<span style="color: #000000; font-weight: bold;">Class</span>;
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Grass Block.png&quot;</span>, mimeType=<span style="color: #ff0000;">'application/octet-stream'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _grassBlock:<span style="color: #000000; font-weight: bold;">Class</span>;
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Plain Block.png&quot;</span>, mimeType=<span style="color: #ff0000;">'application/octet-stream'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _plainBlock:<span style="color: #000000; font-weight: bold;">Class</span>;
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Stone Block.png&quot;</span>, mimeType=<span style="color: #ff0000;">'application/octet-stream'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _stoneBlock:<span style="color: #000000; font-weight: bold;">Class</span>;
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Water Block.png&quot;</span>, mimeType=<span style="color: #ff0000;">'application/octet-stream'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _waterBlock:<span style="color: #000000; font-weight: bold;">Class</span>;
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;../Assets/Images/Level/Wood Block.png&quot;</span>, mimeType=<span style="color: #ff0000;">'application/octet-stream'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _woodBlock:<span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> LevelTiles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			ResourceManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">RegisterEmbeddedResource</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;../Assets/Images/Level/Brown Block.png&quot;</span>, ImageResource, <span style="color: #000000; font-weight: bold;">new</span> _brownBlock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ByteArray<span style="color: #66cc66;">&#41;</span>;
			ResourceManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">RegisterEmbeddedResource</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;../Assets/Images/Level/Dirt Block.png&quot;</span>, ImageResource, <span style="color: #000000; font-weight: bold;">new</span> _dirtBlock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ByteArray<span style="color: #66cc66;">&#41;</span>;
			ResourceManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">RegisterEmbeddedResource</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;../Assets/Images/Level/Grass Block.png&quot;</span>, ImageResource, <span style="color: #000000; font-weight: bold;">new</span> _grassBlock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ByteArray<span style="color: #66cc66;">&#41;</span>;
			ResourceManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">RegisterEmbeddedResource</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;../Assets/Images/Level/Plain Block.png&quot;</span>, ImageResource, <span style="color: #000000; font-weight: bold;">new</span> _plainBlock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ByteArray<span style="color: #66cc66;">&#41;</span>;
			ResourceManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">RegisterEmbeddedResource</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;../Assets/Images/Level/Stone Block.png&quot;</span>, ImageResource, <span style="color: #000000; font-weight: bold;">new</span> _stoneBlock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ByteArray<span style="color: #66cc66;">&#41;</span>;
			ResourceManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">RegisterEmbeddedResource</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;../Assets/Images/Level/Water Block.png&quot;</span>, ImageResource, <span style="color: #000000; font-weight: bold;">new</span> _waterBlock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ByteArray<span style="color: #66cc66;">&#41;</span>;
			ResourceManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">RegisterEmbeddedResource</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;../Assets/Images/Level/Wood Block.png&quot;</span>, ImageResource, <span style="color: #000000; font-weight: bold;">new</span> _woodBlock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ByteArray<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></td></tr></table></div>
<p>Then, to load this, we just use the level manager.  Note the last argument to AddLevelFileReference, which is true.  The means that the sprite data will be persistent, and we won&#8217;t have to rebuild the basic entities of the level every time we load a new level.</p>
<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.enigmaticthought.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=66&amp;download=LevelLoader.as">LevelLoader.as</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6613"><td class="code" id="p66code13"><pre class="actionscript" style="font-family:monospace;">package com.<span style="color: #006600;">enigmatic</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LevelLoader
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">import</span> PBLabs.<span style="color: #006600;">Rendering2D</span>.<span style="color: #006600;">Scene2DComponent</span>;
		<span style="color: #0066CC;">import</span> PBLabs.<span style="color: #006600;">Rendering2D</span>.<span style="color: #006600;">BasicSpatialManager2D</span>;
		<span style="color: #0066CC;">import</span> PBLabs.<span style="color: #006600;">Rendering2D</span>.<span style="color: #006600;">SpriteSheetComponent</span>;
		<span style="color: #0066CC;">import</span> PBLabs.<span style="color: #006600;">Engine</span>.<span style="color: #006600;">Core</span>.<span style="color: #006600;">LevelManager</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> LevelLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> _scene2DComponent:Scene2DComponent;
			<span style="color: #000000; font-weight: bold;">var</span> _managerComponent:BasicSpatialManager2D;
			<span style="color: #000000; font-weight: bold;">var</span> _spriteSheet:SpriteSheetComponent;
&nbsp;
			LevelManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">AddLevelFileReference</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;../Assets/Level/Sprites.xml&quot;</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			LevelManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">AddGroupReference</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SpriteData&quot;</span>,<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>
<p>And finally, to complete the circle, the level itself, in xml.</p>
<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.enigmaticthought.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=66&amp;download=level.xml">level.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6614"><td class="code" id="p66code14"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;level<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wood&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dirt&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;grass&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;plain&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;stone&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;water&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;brown&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wood&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dirt&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;grass&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;plain&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;stone&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;water&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;brown&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dirt&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;grass&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;plain&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;stone&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;water&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;brown&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wood&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dirt&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;grass&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;plain&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;stone&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;water&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;brown&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wood&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;grass&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;plain&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;stone&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;water&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;brown&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wood&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dirt&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;grass&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;plain&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;stone&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;water&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;brown&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;wood&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tile</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dirt&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/level<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>
<p>And now comes the fun part.  I simply use ActionScript&#8217;s ability to work with XML to loop through the level data and add a tile at a time.  Each tile is made of two basic components.  A <a href="http://pushbuttonengine.googlecode.com/svn/site/APIDocs/PBLabs/Rendering2D/SpriteRenderComponent.html">SpriteRenderComponent</a> to display, and a <a href="http://pushbuttonengine.googlecode.com/svn/site/APIDocs/PBLabs/Rendering2D/SimpleSpatialComponent.html"> SimpleSpatialComponent</a> to handle placement.  the order you add components don&#8217;t matter, even if they reference other components.  Pushbutton handles that kind of stuff.</p>
<p>The way pushbutton works, you call a global function AllocateEntity() which returns an IEntity component.  Then you manipulate the entity from there.  The engine handles all the messy work of resource allocation and whatnot.</p>
<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p66code15'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6615"><td class="code" id="p66code15"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> newTile:IEntity = AllocateEntity<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>
<p>Now that we have an entity, we add components to it.  Since I built this off the documented level xml file, I created the Render Component First.</p>
<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p66code16'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6616"><td class="code" id="p66code16"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> render:SpriteRenderComponent = <span style="color: #000000; font-weight: bold;">new</span> SpriteRenderComponent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
render.<span style="color: #006600;">SpriteSheet</span> = NameManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">Lookup</span><span style="color: #66cc66;">&#40;</span>tile.<span style="color: #006600;">attribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">LookupComponentByType</span><span style="color: #66cc66;">&#40;</span>SpriteSheetComponent<span style="color: #66cc66;">&#41;</span> as SpriteSheetComponent;
render.<span style="color: #006600;">PositionReference</span> = <span style="color: #000000; font-weight: bold;">new</span> PropertyReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;@Spatial.Position&quot;</span><span style="color: #66cc66;">&#41;</span>;
render.<span style="color: #006600;">RotationReference</span> = <span style="color: #000000; font-weight: bold;">new</span> PropertyReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;@Spatial.Rotation&quot;</span><span style="color: #66cc66;">&#41;</span>;
render.<span style="color: #006600;">SizeReference</span> = <span style="color: #000000; font-weight: bold;">new</span> PropertyReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;@Spatial.Size&quot;</span><span style="color: #66cc66;">&#41;</span>;
newTile.<span style="color: #006600;">AddComponent</span><span style="color: #66cc66;">&#40;</span>render,<span style="color: #ff0000;">&quot;Render&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>
<p>this is the same as the xml:</p>
<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p66code17'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6617"><td class="code" id="p66code17"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;PBLabs.Rendering2D.SpriteRenderComponent&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Render&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SpriteSheet</span> <span style="color: #000066;">componentReference</span>=<span style="color: #ff0000;">&quot;&lt;tilename&gt;</span></span>&quot;/&gt;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PositionReference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>@Spatial.Position<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PositionReference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RotationReference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>@Spatial.Rotation<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/RotationReference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SizeReference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>@Spatial.Size<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SizeReference<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>
<p>The trickiest part was converting the xml line for the sprite sheet to code.  That&#8217;s where the NameManager comes into play.  All named entities are stored there, and if you refer back to the Sprites.xml file, you&#8217;ll see that the entities are named based on the type.  Once you get the entity, you can pull the type up easily by using the LookupComponent commands.    You can use name or type. The <a href="http://pushbuttonengine.googlecode.com/svn/site/APIDocs/PBLabs/Engine/Serialization/Serializer.html">Serializer</a> handles the sprite sheet lookup for you if your using xml, which is why there was a extra level of depth not in the xml.</p>
<p>Next is the spatial manager that handles the placement of the tile.</p>
<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p66code18'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6618"><td class="code" id="p66code18"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> spatial:SimpleSpatialComponent = <span style="color: #000000; font-weight: bold;">new</span> SimpleSpatialComponent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
spatial.<span style="color: #006600;">SpatialManager</span> = <span style="color: #66cc66;">&#40;</span>NameManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">Lookup</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SimpleSpatial&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">LookupComponentByName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Manager&quot;</span><span style="color: #66cc66;">&#41;</span> as ISpatialManager2D;
spatial.<span style="color: #0066CC;">Position</span> = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>x <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">50</span>, y <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#41;</span>;
spatial.<span style="color: #006600;">QueryMask</span> = <span style="color: #000000; font-weight: bold;">new</span> ObjectType<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
spatial.<span style="color: #006600;">QueryMask</span>.<span style="color: #006600;">TypeNames</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Floor&quot;</span>,<span style="color: #ff0000;">&quot;Renderable&quot;</span><span style="color: #66cc66;">&#93;</span>;
spatial.<span style="color: #0066CC;">Size</span> = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">85</span><span style="color: #66cc66;">&#41;</span>;
newTile.<span style="color: #006600;">AddComponent</span><span style="color: #66cc66;">&#40;</span>spatial,<span style="color: #ff0000;">&quot;Spatial&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>
<p>this is the same as the xml:</p>
<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p66code19'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6619"><td class="code" id="p66code19"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;component</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;PBLabs.Rendering2D.SimpleSpatialComponent&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Spatial&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SpatialManager</span> <span style="color: #000066;">componentReference</span>=<span style="color: #ff0000;">&quot;SimpleSpatial&quot;</span> <span style="color: #000066;">componentName</span>=<span style="color: #ff0000;">&quot;Manager&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;QueryMask</span> <span style="color: #000066;">childType</span>=<span style="color: #ff0000;">&quot;String&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;_0<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Floor<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/_0<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;_1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Renderable<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/_1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/QueryMask<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Position<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;x<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>50<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/x<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;y<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>50<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/y<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Position<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Size<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;x<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>50<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/x<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;y<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>85<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/y<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Size<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>
<p>Again, the Spatial Manager was the most complicated, but the extra level was also included in the xml.   The other item to note is the QueryMask.  This is what the RenderMask is referring to in the Scene from Sprite.xml.  If you are using a <a href="http://pushbuttonengine.googlecode.com/svn/site/APIDocs/PBLabs/Box2D/Box2DSpatialComponent.html">Box2DSpatialComponent</a> instead, the RenderMask matches up against the CollidesWithTypes, which is what the demo program is using.</p>
<p>Here is the completed function.  Make sure you wait until the level loading is complete (simply add an even listener for a LevelEvent.LOADED_EVENT) or you&#8217;ll run into null references due to a partially loaded level.</p>
<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.enigmaticthought.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=66&amp;download=buildLevel.as">buildLevel.as</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6620"><td class="code" id="p66code20"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> buildLevel<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">xml</span>:<span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> x:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
	<span style="color: #000000; font-weight: bold;">var</span> y:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
	<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> row:<span style="color: #0066CC;">XML</span> <span style="color: #b1b100;">in</span> <span style="color: #0066CC;">xml</span>.<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> tile:<span style="color: #0066CC;">XML</span> <span style="color: #b1b100;">in</span> row.<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> newTile:IEntity = AllocateEntity<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> render:SpriteRenderComponent = <span style="color: #000000; font-weight: bold;">new</span> SpriteRenderComponent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			render.<span style="color: #006600;">SpriteSheet</span> = NameManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">Lookup</span><span style="color: #66cc66;">&#40;</span>tile.<span style="color: #006600;">attribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">LookupComponentByType</span><span style="color: #66cc66;">&#40;</span>SpriteSheetComponent<span style="color: #66cc66;">&#41;</span> as SpriteSheetComponent;
			render.<span style="color: #006600;">PositionReference</span> = <span style="color: #000000; font-weight: bold;">new</span> PropertyReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;@Spatial.Position&quot;</span><span style="color: #66cc66;">&#41;</span>;
			render.<span style="color: #006600;">RotationReference</span> = <span style="color: #000000; font-weight: bold;">new</span> PropertyReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;@Spatial.Rotation&quot;</span><span style="color: #66cc66;">&#41;</span>;
			render.<span style="color: #006600;">SizeReference</span> = <span style="color: #000000; font-weight: bold;">new</span> PropertyReference<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;@Spatial.Size&quot;</span><span style="color: #66cc66;">&#41;</span>;
			newTile.<span style="color: #006600;">AddComponent</span><span style="color: #66cc66;">&#40;</span>render,<span style="color: #ff0000;">&quot;Render&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> spatial:SimpleSpatialComponent = <span style="color: #000000; font-weight: bold;">new</span> SimpleSpatialComponent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			spatial.<span style="color: #006600;">SpatialManager</span> = <span style="color: #66cc66;">&#40;</span>NameManager.<span style="color: #006600;">Instance</span>.<span style="color: #006600;">Lookup</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SimpleSpatial&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">LookupComponentByName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Manager&quot;</span><span style="color: #66cc66;">&#41;</span> as ISpatialManager2D;
			spatial.<span style="color: #0066CC;">Position</span> = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span>x <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">50</span>, y <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#41;</span>;
			spatial.<span style="color: #006600;">QueryMask</span> = <span style="color: #000000; font-weight: bold;">new</span> ObjectType<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			spatial.<span style="color: #006600;">QueryMask</span>.<span style="color: #006600;">TypeNames</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;Floor&quot;</span>,<span style="color: #ff0000;">&quot;Renderable&quot;</span><span style="color: #66cc66;">&#93;</span>;
			spatial.<span style="color: #0066CC;">Size</span> = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">85</span><span style="color: #66cc66;">&#41;</span>;
			newTile.<span style="color: #006600;">AddComponent</span><span style="color: #66cc66;">&#40;</span>spatial,<span style="color: #ff0000;">&quot;Spatial&quot;</span><span style="color: #66cc66;">&#41;</span>;
			x += <span style="color: #cc66cc;">1</span>;
&nbsp;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
		x = <span style="color: #cc66cc;">0</span>;
		y += <span style="color: #cc66cc;">1</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>
<p><a href="http://flex.enigmaticthought.com/LoadViaCode/LoadViaCode.html">Here is the final result with source code</a>. It&#8217;s not much to look at, but it should get you started.</p>
<p>The next step is to create a custom TilemapRendererComponent that would do a lot of the heavy lifting for me.  Things like positioning of the tiles based on the grid and having to work with each individual tile.  Of course, the point of this post wasn&#8217;t tiles, but the entities that happened to be tiles, so that&#8217;s a whole other topic to cover later<br />
<h3 class='related_post_title'>Related Posts (generated):</h3>
<ul class='related_post'>
<li><a href='http://enigmaticthought.com/2010/06/flash-debug-crashing-in-firefox/' title='Flash Debug crashing in Firefox?'>Flash Debug crashing in Firefox?</a></li>
<li><a href='http://enigmaticthought.com/2009/12/why-algorithms-matter/' title='Why Algorithms Matter'>Why Algorithms Matter</a></li>
<li><a href='http://enigmaticthought.com/2009/11/scientific-notation-patch-accepted/' title='Scientific Notation Patch Accepted'>Scientific Notation Patch Accepted</a></li>
<li><a href='http://enigmaticthought.com/2009/09/flash-builders-new-menu/' title='Altering Flash Builder&#8217;s new menu'>Altering Flash Builder&#8217;s new menu</a></li>
<li><a href='http://enigmaticthought.com/2009/08/how-to-flex-the-twitter-api/' title='How to Flex the Twitter API'>How to Flex the Twitter API</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.enigmaticthought.com/2009/04/adding-pushbutton-engine-entities-via-code/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
