<?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>FlexWiz Blog</title>
	<atom:link href="http://blog.flexwiz.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexwiz.net</link>
	<description>On Game Development and the Flash platform</description>
	<lastBuildDate>Sat, 17 Dec 2011 22:46:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>SpriteSheet Animation in AS3</title>
		<link>http://blog.flexwiz.net/spritesheet-animation-in-as3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spritesheet-animation-in-as3</link>
		<comments>http://blog.flexwiz.net/spritesheet-animation-in-as3/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 20:33:05 +0000</pubDate>
		<dc:creator>theWiz</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[Blitting]]></category>
		<category><![CDATA[SpriteSheet]]></category>
		<category><![CDATA[TexturePacker]]></category>

		<guid isPermaLink="false">http://blog.flexwiz.net/?p=919</guid>
		<description><![CDATA[Over the last few years sprite-sheet animation gained popularity among game developers. It offers some real advantages over movie clips &#8211; lighter and potentially faster performance, with the added bonus of code portability. If you plan to deploy your game on Android and iOS  as well, this is definitely the way to go. I found that most [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-934" title="sheetDemo3ab" src="http://blog.flexwiz.net/wp-content/uploads/2011/11/sheetDemo3ab-300x258.png" alt="" width="300" height="258" />Over the last few years sprite-sheet animation gained popularity among game developers. It offers some real advantages over movie clips &#8211; lighter and potentially faster performance, with the added bonus of code portability. If you plan to deploy your game on Android and iOS  as well, this is definitely the way to go.</p>
<p>I found that most of the tutorials on sprite sheets are for the Cocos2D engine (in Objective-C for iOS). Here I will show a practical and convenient way to animate sprite sheets in AS3, making the game perform well on both Flash in browser and AIR mobile.</p>
<p><span id="more-919"></span></p>
<p>There are a few off the shelf engines that use variations of spritesheets, among them Starling (Flash 11 only) and Flixel. These may be perfect for certain type of projects, but I decided to write my own classes to minimize the dependency on 3rd party code.</p>
<h3>Demo</h3>
<div class="wp-caption aligncenter" style="width: 540px"><a href="http://blog.flexwiz.net/sources/animSprite/AnimDemo.swf"><img title="demo" src="http://blog.flexwiz.net/wp-content/uploads/2011/12/demo1a.png" alt="" width="530" height="394" /></a><p class="wp-caption-text">Click image to see the demo</p></div>
<p>Download the full <a href="https://bitbucket.org/flexwiz/spritesheet" target="_blank">demo code</a> from BitBucket <a href="https://bitbucket.org/flexwiz/spritesheet" target="_blank">here</a>.</p>
<h3>The Tools</h3>
<p>You would need a code IDE (FlashDevelop, FDT or Flash Builder) and an image tool that can pack textures. I use the popular <a href="http://www.texturepacker.com/" target="_blank">TexturePacker</a>, in my opinion the best texture tool for developers. If anyone knows anything better, please comment.</p>
<h3>Preparing the assets</h3>
<p>The animated sprite is created by the artist  with their animation package of choice. This is a sequence of images that form the animation frames.  In this case (and most others) all frames are the same size.</p>
<p>Open TexturePacker and import the individual images into the projects. Select json as the data format, check &#8216;Allow free sizes&#8217; and make sure &#8216;Allow rotation&#8217; is not checked. Publish the texture to the output folder. <a href="http://blog.flexwiz.net/wp-content/uploads/2011/12/settings.png" target="_blank">The setting I use</a> can be seen <a href="http://blog.flexwiz.net/wp-content/uploads/2011/12/settings.png" target="_blank">here</a>.</p>
<p>There are many different options with TexturePacker, that are out of scope of this article. For more in depth look, check out Chris Fletcher&#8217;s tutorial <a href="http://chris-fletcher.com/tag/texturepacker-tutorial/" target="_blank">here</a>.</p>
<p>Once published, you end up with a large PNG file &#8211; the texture sheet, and a json file to go with it.</p>
<h3>Reading the texure with the AnimTextureSheet class</h3>
<p>I created the AnimTextureSheet class to encapsulate a texture sheet and its data. After loading your animation assets, you get a BitmapData from the sheet PNG and a string from the json file. After decoding the json string, the function populateFrameArray serialize the frame data into an array which is then passed into the  newly created AnimTextureSheet.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">	<span style="color: #6699cc; font-weight: bold;">var</span> seqRaw<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = JSON<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">decode</span><span style="color: #000000;">&#40;</span> sheetData <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> animData<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span>= <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
	populateFrameArray<span style="color: #000000;">&#40;</span>animData<span style="color: #000066; font-weight: bold;">,</span> seqRaw<span style="color: #000066; font-weight: bold;">.</span>frames<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Sort</span>
	animData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sortOn</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;id&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Create and initialize the tile sheet</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> tileSheet<span style="color: #000066; font-weight: bold;">:</span>AnimTextureSheet= <span style="color: #0033ff; font-weight: bold;">new</span> AnimTextureSheet<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	tileSheet<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>texture<span style="color: #000066; font-weight: bold;">,</span> animData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Once initialized, the tille sheet is ready to go, and the  drawFrame() method can be called to blit a frame into a destination bitmap buffer.</p>
<p><strong>UPDATE</strong><br />
When compiling with Flash Player 11 (or Flex 4.6) there is a build error due to the new native JSON parser:<br />
<code>Can not resolve a multiname reference unambiguously. JSON [..]</code><br />
To resolve the problem, simply change the first line to read:<br />
<code>var seqRaw:Object =  com.adobe.serialization.json.JSON.decode( sheetData );</code></p>
<h3>Play it</h3>
<p>To actually display the animation,  we need a display object to hold the bitmap. For that purpose I created the AnimSprite class, that is based on flash.display.Bitmap. This class in only for convenience - you can create your own &#8211; it demonstrates the possible use cases for an animated sprite.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">	<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createAnim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>AnimSprite
	<span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> anim<span style="color: #000066; font-weight: bold;">:</span>AnimSprite = <span style="color: #0033ff; font-weight: bold;">new</span> AnimSprite<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		anim<span style="color: #000066; font-weight: bold;">.</span>initialize<span style="color: #000000;">&#40;</span>_texSheet<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		anim<span style="color: #000066; font-weight: bold;">.</span>addSequence<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;all&quot;</span><span style="color: #000066; font-weight: bold;">,</span> arFrames<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">16</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		anim<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;all&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">return</span> anim<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">// Call on enter frame event</span>
	<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> onFrameUpdate<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">pause</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> arSprites<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> 	<span style="color: #000000;">&#123;</span>
			AnimSprite<span style="color: #000000;">&#40;</span>arSprites<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>updateAnimation<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The above code shows how AnimSprite is actually used.</p>
<ol>
<li>instantiate the AnimSprite</li>
<li>initialize it with  a tile sheet</li>
<li>add one or more sequences (indexed frames) with an individual frame rate</li>
<li>add it to the stage.</li>
</ol>
<p>To play it:</p>
<ol>
<li>Call play() to start playing a sequence</li>
<li>call updateAnimation() on every frame</li>
</ol>
<h3>How it works</h3>
<p>AnimSprite uses partial blitting technique to animate. It uses the bitmapData as a frame buffer that holds the frame image that gets displayed. On every update, the updateAnimation()  function checks if the animation frame need to advance, and if so calls advanceFrame() &#8211; that sets the dirty flag when the current frame index is changed.  The the following method is then used to draw the frame:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">	<span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> drawFrameInternal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
	<span style="color: #000000;">&#123;</span>
		dirty = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">fillRect</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rect</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		mAnimSheet<span style="color: #000066; font-weight: bold;">.</span>drawFrame<span style="color: #000000;">&#40;</span>curIndex<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Check out the code for more details on the AnimSprite class.</p>
<p>That&#8217;s pretty much it. Let me know if you find any bugs or problems.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexwiz.net/spritesheet-animation-in-as3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Make Your Own Level Editor &#8211; Part II</title>
		<link>http://blog.flexwiz.net/make-your-own-level-editor-part-ii/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=make-your-own-level-editor-part-ii</link>
		<comments>http://blog.flexwiz.net/make-your-own-level-editor-part-ii/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 09:28:49 +0000</pubDate>
		<dc:creator>theWiz</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[Contents]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.flexwiz.net/?p=900</guid>
		<description><![CDATA[On part 1 of this series, I outlined the basic principles of handling the content pipeline, and how the process should work. To continue, we move on to building the level. As mentioned on part 1, I use the Flash IDE (CS4 or CS5) because of its support for automation and custom commands. Basic familiarity with Flash is [...]]]></description>
			<content:encoded><![CDATA[<p>On <a title="Make Your Own Level Editor – Part I" href="http://blog.flexwiz.net/make-your-own-level-editor-part-i/">part 1 of this series</a>, I outlined the basic principles of handling the content pipeline, and how the process should work. To continue, we move on to building the level. As mentioned on part 1, I use the Flash IDE (CS4 or CS5) because of its support for automation and custom commands. Basic familiarity with Flash is required.<span id="more-900"></span></p>
<p style="padding-left: 30px;"><em>This article is cross posted on<a title="#AltDevBlogADay" href="http://altdevblogaday.com/2011/09/10/make-your-own-level-editor-part-ii/" target="_blank"> #AltDevBlogADay</a>. See my <a href="http://altdevblogaday.com/author/amos-laber/" target="_blank">other articles</a> published on #AltDevBlogADay <a href="http://altdevblogaday.com/author/amos-laber/" target="_blank">here</a>.</em></p>
<h4>Mapping Objects and Assets</h4>
<p><img class="size-full wp-image-16271 alignright" style="margin-left: 8px; margin-right: 8px;" src="http://altdevblogaday.com/wp-content/uploads/2011/09/edit02.png" alt="" width="482" height="375" /></p>
<p>Before actually making the first level, we need to create a manifest of all game objects. These can be anything from background elements, pick-ups or characters. Most are represented by static bitmaps or sprites-sheets where the game object is displayed using a single asset.</p>
<p>The idea is to map a logical game object (class) to a physical asset (bitmap or simple shape). For simplicity, we assume the size of the asset defines the bounding box of the logical game object. Each entry in the manifest will pair the class name with the asset file name, and a class ID. Its recommended to use some kind of naming convention with prefixes etc.</p>
<h4>Building the Basic Level</h4>
<p>Next we create a level template. This is a project with an empty level that would serve as a base for all future levels. Create a new Flash project (fla) and import all your assets into the library and save the file.</p>
<p>Flash keeps library objects either as the source assets or movie-clips, with the latter used as a container for a display object that can be manipulated.<br />
For each of the source assets, create a movieclip for it (using F8), and name it to match the class id in the manifest. Save the file and start dragging objects to the stage. You can define a layer for graphic elements that are not exported and place there references, guides and bitmaps from the mock up. Make sure to have a rectangle that represents the screen bounds.Use the first level as template for the rest, reusing the same library objects.</p>
<h4>Exporting the Level</h4>
<p>The flash project file (fla) is how a levels is saved. This would be an intermediate file that will only be used to modify the level on design time. To actually use it in the game, we need to export the level data to a format that can be loaded at runtime.</p>
<p>Export the level data means we serialize it to XML, which will contain entries for all instances of game objects, each with is metadata (like class name, position, rotation and size). For that, we make use of JSFL &#8211; the JavaScript Flash API that&#8217;s included with the Flash IDE.</p>
<p>The following JSFL script creates an XML file and saves it in the current folder. To run, use Commands -&gt; &#8216;Run Command&#8217; and then point to the script file (should be saved with jsfl extension). After the first run, the script name will appear under the &#8216;Commands&#8217; menu for quick access.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//==========================================</span>
<span style="color: #006600; font-style: italic;">//</span>
<span style="color: #006600; font-style: italic;">// Export all stage instances to xml</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> doc <span style="color: #339933;">=</span> fl.<span style="color: #660066;">getDocumentDOM</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	doc.<span style="color: #660066;">selectAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> sel <span style="color: #339933;">=</span> fl.<span style="color: #660066;">getDocumentDOM</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">selection</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> myXml <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> iLen <span style="color: #339933;">=</span> sel.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> iLen<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #339933;">=</span> sel<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s.<span style="color: #660066;">instanceType</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;symbol&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
		myXml <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;    &lt;child type='&quot;</span> <span style="color: #339933;">+</span> s.<span style="color: #660066;">libraryItem</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #339933;">;</span>
		myXml <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot; x='&quot;</span> <span style="color: #339933;">+</span> s.<span style="color: #660066;">x</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;' y='&quot;</span> <span style="color: #339933;">+</span> s.<span style="color: #660066;">y</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #339933;">;</span>
		myXml <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot; rotation='&quot;</span> <span style="color: #339933;">+</span> s.<span style="color: #660066;">rotation</span><span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #339933;">;</span>
		myXml <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	doc.<span style="color: #660066;">selectNone</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        myXml <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;&lt;/level&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	flash.<span style="color: #660066;">outputPanel</span>.<span style="color: #660066;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	flash.<span style="color: #660066;">trace</span><span style="color: #009900;">&#40;</span>myXml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> exportFileName <span style="color: #339933;">=</span> doc.<span style="color: #660066;">pathURI</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/%20/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot; &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #000066;">name</span><span style="color: #339933;">,</span>
                                doc.<span style="color: #000066;">name</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\.fla$/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	flash.<span style="color: #660066;">outputPanel</span>.<span style="color: #660066;">save</span><span style="color: #009900;">&#40;</span>exportFileName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	flash.<span style="color: #660066;">trace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;File saved to &quot;</span> <span style="color: #339933;">+</span> exportFileName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Here is a sample of the resulting file:</p>
<p><img class="size-full wp-image-16255 alignnone" style="margin-top: 10px; margin-bottom: 10px;" src="http://altdevblogaday.com/wp-content/uploads/2011/09/SampleXml.gif" alt="" width="616" height="158" /><br />
A major advantage of this export is the ability to easily customize the XML data by changing the script to add different properties for each entry (lines 15-18).</p>
<p>&nbsp;</p>
<h4>Loading the Level</h4>
<div>Loading the level into the game is a matter of de-serializing the XML data into game objects. This is truly platform agnostic: you could read the XML from any language or platform and parse the results however you like. The most common are for Flash, iOS and XNA.</div>
<div>The process for loading should be something like:</div>
<blockquote>
<ol>
<li>Read list of game objects from XML into an array.</li>
<li>Iterate on the array. For each item:
<ol>
<li>Pass the class name to a factory method to create a new instance of the object.</li>
<li>Locate the asset (resource) associated with the object, by looking it up on the object manifest map.</li>
<li>Call the init function on the newly created instance, to populate it with the asset and metadata.</li>
<li>Place the object on stage</li>
</ol>
</li>
<li>End</li>
</ol>
</blockquote>
<p>Your mileage may vary, but that should do the trick. Here I assume all game entity classes are based on one base class, and make use of polymorphism to construct and populate them.</p>
<p>&nbsp;</p>
<h3>Round Trip and Edit Cycle</h3>
<div>
<p>As mentioned before, the level is also saved as a native &#8216;fla&#8217; file, as intermediate, so it can be loaded and exported at any later time. The most effective way to edit a level is by instant round tripping between the game (preview) and the editor. Round tripping is the process of moving from runtime back to design in order to edit or modify the level data.</p>
<div id="attachment_16333" class="wp-caption aligncenter" style="width: 595px"><img class="size-full wp-image-16333 " src="http://altdevblogaday.com/wp-content/uploads/2011/09/chart3a.png" alt="" width="585" height="294" /><p class="wp-caption-text">Round Tripping</p></div>
<p>With a build of the game ready to run and the export script in place, this is made possible.Typically, the designer will have the level editor still open after exporting the data. Running the game will load the data and serve as a preview. If the game runs on a browser its only a matter of refreshing it to reload new data. Now all that is left to do is follow the sequence:  Edit &#8211;  Export &#8211;  Preview, rinse and repeat.</p>
</div>
<div>
<h4>Extending the Loader</h4>
<p>The described method works well for simple game objects that are based on a single asset. However, not all objects are simple. Some object are logical only with no assets, but we still want to be able to place them and get visual indication. Such are trigger boxes, waypoints and spawn points. For these we can create simple shapes (like a semi transparent box or some icon) and use proxy assets.<br />
There is also the option of putting more data into each object. As long as there is a convenient way of entering meta-data in the editor, it can be exported with the object. An example of that would be a ‘fail zone’ &#8211; an invisible trigger box that triggers a level fail when touched by the player object. So a generic trigger box can be extended with a message code (integer or string) that will be specified in the editor &#8211; opening the possibility for the designer to control simple game logic in different scenarios.<br />
These type of ‘programmable’ object not only save time, but also frees the designer to experiment and quickly try out different layouts and configurations without requiring further coding.</p>
<h4>Conclusion</h4>
<p>Sophisticated level editing should not be an exclusive perk of heavy platforms the likes of Unreal3. With little effort, even small indie developers can come up with decent tools to help take control over content pipeline and speed up game content creation.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexwiz.net/make-your-own-level-editor-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make Your Own Level Editor &#8211; Part I</title>
		<link>http://blog.flexwiz.net/make-your-own-level-editor-part-i/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=make-your-own-level-editor-part-i</link>
		<comments>http://blog.flexwiz.net/make-your-own-level-editor-part-i/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 22:00:35 +0000</pubDate>
		<dc:creator>theWiz</dc:creator>
				<category><![CDATA[Workflow]]></category>
		<category><![CDATA[Contents]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.flexwiz.net/?p=883</guid>
		<description><![CDATA[Like anyone working on an indie game, one part that is often neglected is level editing tool. Coders like to focus on the game mechanic and framework and will opt for some hardcoded level with minimal assets. While that may work for a while, it is short sighted. This article is cross posted on #AltDevBlogADay. See [...]]]></description>
			<content:encoded><![CDATA[<p>Like anyone working on an indie game, one part that is often neglected is level editing tool. Coders like to focus on the game mechanic and framework and will opt for some hardcoded level with minimal assets. While that may work for a while, it is short sighted.<br />
<span id="more-883"></span><br />
<em>This article is cross posted on<a title="#AltDevBlogADay" href="http://altdevblogaday.com/2011/09/10/make-your-own-level-editor-part-i/" target="_blank"> #AltDevBlogADay</a>. See my <a href="http://altdevblogaday.com/author/amos-laber/" target="_blank">other articles</a> published on #AltDevBlogADay <a href="http://altdevblogaday.com/author/amos-laber/" target="_blank">here</a>.</em></p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-16171" src="http://blog.flexwiz.net/wp-content/uploads/2011/09/BlackSkullEditor.jpg" alt="" width="300" height="222" /></p>
<h3>Taking control of the Content</h3>
<p>A better approach would be start working on tools and tools integration even before writing any code. Working on a 2D game like platformer or a side scroller, one of the first things you need is a decent level editor and to setup a content pipeline for game level data.<br />
One possible solution would be to roll your own full featured editor. This would require a substantial amount of time and resources, and divert the focus for the game to tools. In my experience, this is not very practical if your goal is to get going quickly and work on the actual game.A much quicker solution would be to leverage existing editing tools to create the game levels.<br />
One such tool is the Flash IDE (Flash CS4/CS5) &#8211; it has powerful editing features and is very easy to use. In a recent game project I managed to save time by using it to build my own levels. Since Flash is commonly used to build levels for nearly a decade, many developers found ways to customize it to their needs.</p>
<div>
<h3>The Content Pipeline</h3>
<p><img class="size-medium wp-image-16168 alignright" style="margin: 6px;" src="http://blog.flexwiz.net/wp-content/uploads/2011/09/pipeline_wide1b-300x125.jpg" alt="" width="300" height="125" /></p>
<p>To borrow a phrase fro the Microsoft XNA docs, the content pipeline is a set of processes applied when a game that includes art assets is built. The process starts with an art asset in its original form as a file, and continues to its transformation as data that can be retrieved and used within the game. The goal is to have it set up so that artists and designers can place, modify and preview game assets quickly and easily. In the case of a small scale 2D game you’d want to make it as simple as possible.</p>
<p>While different platforms use different asset types, I will focus on the ones that are common in 2D games for mobile and web platforms. These feature heavy usage of bitmap assets for characters, background and game elements, and some form of descriptive data file (like XML) for levels.</p>
<h3>Design Time vs. Run Time</h3>
<p>The pipeline itself is processed at design time and ends at run time, when the game loads a level with its related assets.  Larger game platforms often use asset processing to create highly optimized versions of the assets for runtime based on the design time assets.  In the case of simple 2D  game, and in order to simplify, the graphical assets that are used in design time are the same one used at run-time &#8211;  this will do just  fine for most cases.<br />
<img class="size-full wp-image-896 aligncenter" title="Pipeline2b" src="http://blog.flexwiz.net/wp-content/uploads/2011/09/Pipeline2b.png" alt="" width="478" height="228" /></p>
<p>In this process, we first arrange the bitmap assets used in a specific level and import them into the editor as library items. Then the level is created by placing instances of these items in the editor, and gets saved to an intermediate format. To prepare for runtime, the level is exported to an  XML level file that contains references to the game assets. Finally when the game loads, it reads the level file and graphical assets to populate the game level.<br />
In addition, round tripping between runtime and design time is made possible, so that a designer can instantly modify the level in the editor and preview the changes in the game.</p>
<h4>More to come</h4>
<p>In Part 2, I will walk trough the  actual steps for building and exporting a game level and handling different game assets.</p>
<p>&nbsp;</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexwiz.net/make-your-own-level-editor-part-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Molehill and the DisplayList &#8211; A Step Back?</title>
		<link>http://blog.flexwiz.net/molehill-and-the-displaylist-a-step-back/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=molehill-and-the-displaylist-a-step-back</link>
		<comments>http://blog.flexwiz.net/molehill-and-the-displaylist-a-step-back/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 21:00:51 +0000</pubDate>
		<dc:creator>theWiz</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Blitting]]></category>
		<category><![CDATA[Molehill]]></category>

		<guid isPermaLink="false">http://blog.flexwiz.net/?p=629</guid>
		<description><![CDATA[There has been a lot of buzz about  Molehill (or Stage3D) and GPU hardware acceleration in the upcoming Flash player 11. However, very little was said on the practical aspects on normal flash applications and games.  Now that the public beta is out, we can get a feel of what it really is, and see [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-868" title="" src="http://blog.flexwiz.net/wp-content/uploads/2011/07/molehill-300x164.png" alt="" width="300" height="164" />There has been a lot of buzz about  Molehill (or Stage3D) and GPU hardware acceleration in the upcoming Flash player 11. However, very little was said on the practical aspects on normal flash applications and games.  Now that the public beta is out, we can get a feel of what it really is, and see what you can and cannot do with it.</p>
<p>Here is my take on the issue of Stage3D/Molehill. While reading related tweets and posts, I notice a few misconceptions about Molehill &#8211; and this is something I’d like to address here.<br />
<span id="more-629"></span></p>
<h4>Dude, where is my Display List?</h4>
<p>Right from the start I felt something doesn&#8217;t feel right. If all the demos are using engines like Away3D, what&#8217;s in it for &#8216;plain&#8217; flash games? Apparently, Molehill (and Flash 11) does not include GPU hardware acceleration for the Display List.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-869" src="http://blog.flexwiz.net/wp-content/uploads/2011/07/zombie.jpg" alt="" width="468" height="265" /></p>
<p>First of all a note about architecture. Flash uses a retained mode rendering model, through its Display List. It means we don&#8217;t actually draw, we place display objects on the display list (and the stage) &#8211; the rest is done by the Flash player, where the drawing actually takes place on every frame.</p>
<p>In contrast, Moelhill API  is a thin wrapper for OpenGL  (or Direct3D in some cases) that provides low level drawing of 3D geometry and textures, including programmable shaders. It exists outside of the flash stage, almost as a standalone system. It is not designed to support, or implement drawing of display objects.</p>
<p>While not without its problems, the flash display list is the core feature of Flash: a simple and easy to use scene graph that gets processed and rendered on every frame. Its what makes Flash Flash: you would not want to imagine building any games or applications without it.</p>
<h4>Catching up to current technologies</h4>
<p>This year we started seeing GPU hardware acceleration in JavaScript/CSS, although not on all browsers. Browser have rendering engines that can accelerate primitive drawing for vectors and font when rasterizing them to canvas. I would expect no less from the flash player.<br />
The days when non-accelerated Display List was sufficient for developers are over. Here is what <a href="http://blog.bengarney.com/" target="_blank">Ben Garney</a>, a flash game heavyweight, says on <a href="http://blog.bengarney.com/2010/10/18/the-flash-display-list-and-games/" target="_blank">his blog</a>:</p>
<blockquote><p>[...] I use the display list for lots of things, just like any Flash developer. It’s a useful, flexible, and powerful tool.</p>
<p>But when I have specific, performance oriented needs, I ditch it in favor of something I can control completely. That’s why I always use a raster pipeline – drawing all my own pixels – for my game rendering. Using BitmapData.copyPixels has a consistent, reliable cost, whereas the cost of drawing a DisplayObject hierarchy, either on stage or via draw(), is highly variable and difficult to predict in terms of both memory and CPU consumption. [...]</p></blockquote>
<p>So developers like Ben Garney are opting to write their own renderers in order to gain better performance, but that is not an ideal long term solution. A much better one would be to utilize both multi-threading and GPU hardware acceleration for the standard flash Display List.</p>
<h4>Hello 1993</h4>
<p>For me, this is Deja vu all over again. It brings memories of the early 90s, were all we had was raw OpenGL or DirectX, and programming 3D was considered a black magic, some sort of witchcraft. We had to use special bitmap fonts and skimp on UI features for games, because everything was done in low-level, with no component libraries to speak of.<br />
A lot has changed since then, both in technologies and standards. Are we are expected to use the low level Molehill or use a Molehill based 3D engine for any plain old 2D project?</p>
<div id="attachment_865" class="wp-caption aligncenter" style="width: 410px"><a href="http://blog.flexwiz.net/wp-content/uploads/2011/05/1993-Ford-Mustang.jpg"><img class="size-full wp-image-865 " title="1993-Ford-Mustang" src="http://blog.flexwiz.net/wp-content/uploads/2011/05/1993-Ford-Mustang.jpg" alt="" width="400" height="300" /></a><p class="wp-caption-text">1993 Ford Mustang</p></div>
<p>Bringing GPU acceleration to a small subset of flash applications just won&#8217;t cut it. Casual games that make a large part of Flash projects, need fast performing 2D display as well as complex UI. Forcing developers to shoehorn Molehill into any 2D project is just wrong. It&#8217;s not a good solution and would push more Flash developers to jump ship and look for alternatives.</p>
<h4>GPU Acceleration for All</h4>
<p>Don’t get me wrong: I am a 3D enthusiast myself, and did a lot of 3D programming on different games way before I started using Flash &#8211; and 3D API in flash is better than none. I simply don’t like the idea of having to choose between hardware acceleration or the Display List and not both of them together.</p>
<p>The next logical step for Adobe would be to build GPU hardware acceleration into the Flash Display List, so that the bottleneck of scene rendering would be removed. Yes, it carries some risks since Flash would become dependent on display driver vendors to run consistently on different platforms, but surely this can be resolved by partnering with nVidia and AMD. If done correctly, any existing AS3 code would be accelerated without any changes.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexwiz.net/molehill-and-the-displaylist-a-step-back/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

