<?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>Producerism &#187; Blog</title>
	<atom:link href="http://producerism.com/category/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://producerism.com</link>
	<description>Thomas Gorence: Interactive Developer (Orlando, FL)</description>
	<lastBuildDate>Wed, 09 May 2012 12:15:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Orlando WordPress Meetup 03/21/2012 Recap</title>
		<link>http://producerism.com/blog/orlando-wordpress-meetup-03212012-recap/</link>
		<comments>http://producerism.com/blog/orlando-wordpress-meetup-03212012-recap/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 00:25:59 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=1165</guid>
		<description><![CDATA[So I attended my second meetup ever this week, and even got to present on some useful resources for wordpress developers, designers and general users.  Here is a quick recap of my presentation, along with a few other things mentioned at the meetup. 5 Useful Resources (for WordPress) My topic was "5 useful resources" for [...]]]></description>
			<content:encoded><![CDATA[<p>So I attended my second meetup ever this week, and even got to present on some useful resources for wordpress developers, designers and general users.  Here is a quick recap of my presentation, along with a few other things mentioned at the meetup.</p>
<h1>5 Useful Resources (for WordPress)</h1>
<p>My topic was "5 useful resources" for wordpress, and originally I was going to start off with version control with svn or git - but I later decided to tone it down a little and focus on things that would help non-developers (which ended up being a good decision).  Here's what I finally settled on:</p>
<h2>#1: <a href="http://www.balsamiq.com/products/mockups">Balsamiq Mockups</a></h2>
<p>Balsamiq Mockups is an AIR-based cross-platform program / web-app with the sole focus of making the conceptual design process smoother.  It allows you to focus on the main elements of a website (or app) without getting caught up in the small trivial details.</p>
<p><a href="http://dhrandy.deviantart.com/gallery/#/d24j5v8"><img class="alignnone size-medium wp-image-1171" title="Coffee_Shop_Website_Mockup_by_dhrandy" src="http://producerism.com/wp-content/uploads/2012/03/Coffee_Shop_Website_Mockup_by_dhrandy-800x522.jpg" alt="" width="800" height="522" /></a></p>
<p>Here's a good example of how Balsamiq can be useful.  The design above (credit: <a href="http://dhrandy.deviantart.com/gallery/#/d24j5v8">http://dhrandy.deviantart.com/gallery/#/d24j5v8</a>) is a typical mockup you may create for a client or yourself.  If the client isn't picky about design, then this can be a very fast way of getting things done.  However, if you present a website mockup in the beginning stages, and really just want to get the layout down as opposed to the final design - then sometimes you can get caught talking about what fonts to use, gradient colors, which images to use, etc.  I've been in countless meetings that had to wrap up without much progress because of so much focus on these trivial details early in the process.  Here is why Balsamiq Mockups is so awesome.</p>
<p><img class="alignnone size-full wp-image-1172" title="balsamiq-wiki" src="http://producerism.com/wp-content/uploads/2012/03/balsamiq-wiki.png" alt="" width="768" height="584" /></p>
<p>As you can see nothing on this mockup can be taken literally, and instead of discussing gradients or logo treatment, we can focus on the overall design first.  This is one of the most useful tools I've discovered in the past few years, and it truly does make life much easier.  It's  extremely easy to use, so that non-designers and non-developers can flesh out ideas in detail, without getting overwhelmed or losing their concepts in translation by technoical jargon.  Most of the time, the benefit of using Mockups can be seen instantly - the first project you use it on.  It's a paid product, but there is a free 7 day trial, which should be more than enough time to decide whether it's right for you or not.</p>
<h2>#2: <a href="https://lastpass.com/">LastPass</a></h2>
<p>LastPass helps you deal with the endless number of passwords to keep track of.  Aside from personal passwords to remember, some of us may also have long lists of personal or client blogs to manage.  Not just that, but to be secure about it - each password really should be unique.  Oh, and passwords should not be kept in plaintext files.  So what the hell is the solution?  This one is easy.</p>
<p><img class="alignnone size-full wp-image-1173" title="lastpass" src="http://producerism.com/wp-content/uploads/2012/03/lastpass.png" alt="" width="800" height="600" /></p>
<p>LastPass not only keeps track of all your logins, but it can login automatically for you across all browsers, platforms, and mobile devices.  If you have an internet connection, you will be able to login to any website you need to.  It's pretty self explanatory and well worth looking into.  A couple people at the meetup mentioned similar solutions like <a href="http://keepass.info/">KeePass</a>, which is essentially the same idea however LastPass is used strictly within a web browser, and stores passwords for websites.  KeePass and similar programs can actually store much more information like credit cards, serial numbers, etc. however I haven't found anything else out there which is as easy to use as LastPass.</p>
<h2> #3: Using a VPN (Virtual Private Network)</h2>
<p>Every once in a while, a site that should be up, just magically goes down.  No response, nothing.  Also, sometimes a site will look fine to me but a visitor or client will swear they can't get to it.  Is it cached?  Network problem?  Who knows?  The very first thing I do is check a website called "<a href="http://www.downforeveryoneorjustme.com/">DownForEveryoneOrJustMe.com</a>" although it's also got a much shorter URL:  <a href="http://www.isup.me/">IsUp.me</a></p>
<p><img class="alignnone size-full wp-image-1174" title="isup" src="http://producerism.com/wp-content/uploads/2012/03/isup.png" alt="" width="768" height="547" /></p>
<p>Most of the time, the site is up and there is just a temporary network issue somewhere along the line.  However, if you are ever wondering if a site is being blocked, filtered, or just down for you - this is a quick way of determining the answer.  That brings me to the real solution though, in case you are being filtered or blocked for some reason, VPNs can help out a lot.  To anyone that has to work behind a firewall or in secure environments this isn't anything new - however even if that doesn't describe you, VPNs can be incredibly useful.  The solution I currently use is <a href="https://www.witopia.net/">WiTopia</a>, since they were<a href="http://lifehacker.com/5761226/best-vpn-service-provider-witopia"> rated best on Lifehackr</a> and had very competitive prices.</p>
<p><img class="alignnone size-full wp-image-1175" title="witopia" src="http://producerism.com/wp-content/uploads/2012/03/witopia.png" alt="" width="586" height="599" /></p>
<p>The other big advantage of WiTopia was the number of locations you can connect from.  Basically, your internet connection is routed through one of these locations, so you can bypass caches, firewalls, and see for yourself if there are problems with your website.  Not to mention, this also allows you to access sites that are otherwise international.  If you've ever tried accessing American media from overseas and been blocked due to copyright laws, this fixes that as well (and vice versa - as someone asked if this would allow you to watch BBC videos online from within the US - yes!).</p>
<h2>#4: Dropbox + Portable Apps</h2>
<p>Another Resource which is part of my everyday routine is Dropbox, especially in conjunction with portable apps. In a sentence for anyone not familiar - dropbox is basically a folder that keeps all files inside of it synchronized across your computer, laptop, mobile devices, etc.  Traditionally it's used for sharing documents, backing up files, etc. However it can also be used as a "usb thumb drive" that sits in the cloud, which you can install software to.</p>
<p><a href="http://db.tt/PjNfYEh"><img class="alignnone size-full wp-image-1176" title="dropbox" src="http://producerism.com/wp-content/uploads/2012/03/dropbox.png" alt="" width="722" height="245" /></a></p>
<p>The specific software I mentioned was <a href="http://www.heidisql.com/">HeidiSQL</a>, <a href="http://notepad-plus-plus.org/">Notepad++</a>, and <a href="http://filezilla-project.org/">FileZilla</a>, although here is the full list of portable apps I have installed on my dropbox:</p>
<ul>
<li>FileZilla (FTP/SFTP/SSH client)</li>
<li>HeidiSQL (SQL client)</li>
<li>HostsMan (edit windows hosts file easier)</li>
<li>PuTTY (telnet/ssh client)</li>
<li>Skype (instant message client)</li>
</ul>
<p>A great resource for more apps is <a href="http://portableapps.com/">PortableApps.com</a>:</p>
<p><a href="http://portableapps.com/"><img class="alignnone size-medium wp-image-1178" title="portableapps" src="http://producerism.com/wp-content/uploads/2012/03/portableapps-800x434.png" alt="" width="800" height="434" /></a></p>
<h2>#5: WordPress Migration Script</h2>
<p>Here's a scenario that can be a pain.  If you are putting together a wordpress site locally on your machine before pushing it to a production server, during the database migration any text referencing your old localhost address could still need to be updated.  The Migrate script makes that much easier.  All you do is enter the current URL, then the replacement URL, and hit go.  The script will detect any changes that need to be made before asking you to confirm them.  This is also very helpful for moving a blog to a new domain name.</p>
<p><a href="https://github.com/ErisDS/Migrate">https://github.com/ErisDS/Migrate</a></p>
<p><a href="https://github.com/ErisDS/Migrate"><img class="alignnone size-full wp-image-1179" title="migrate" src="http://producerism.com/wp-content/uploads/2012/03/migrate.jpg" alt="" width="600" height="199" /></a></p>
<h1>Bonus! WP Smush.it</h1>
<p>This was something I had never heard about before the meetup, and an awesome tool I've already implemented on this website: <a href="http://wordpress.org/extend/plugins/wp-smushit/">WP Smush.it</a>.  It basically just compresses all of your image files for you, and can do it in one big batch.  Within 5 minutes I had installed it, and used it to compress all uploaded images pretty easily.  Highly recommended!</p>
<p><a href="http://wordpress.org/extend/plugins/wp-smushit/"><img class="alignnone size-full wp-image-1180" title="smush-screenshot-1" src="http://producerism.com/wp-content/uploads/2012/03/smush-screenshot-1.jpg" alt="" width="728" height="422" /></a></p>
<h1>Conclusion</h1>
<p>The wordpress meetup was great, and I'm looking forward to many more meetups in general.  <a href="http://barcamporlando.org/">BarCamp Orlando</a> is next month as well, which is like a 100 meetups in one, spread all over downtown Orlando bars and pubs.  I'm not sure how many locals check out my blog, but if you're in town - make sure to be there!</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/orlando-wordpress-meetup-03212012-recap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Conspiracy Theory Reviews</title>
		<link>http://producerism.com/blog/conspiracy-theory-reviews/</link>
		<comments>http://producerism.com/blog/conspiracy-theory-reviews/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 19:51:08 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=1125</guid>
		<description><![CDATA[Here's something a little different.  Anyone that's known me personally for a while probably knows I have three main passions: music, technology, and researching conspiracy theories.  I get some flak for it occasionally, however it's usually just the typical tin foil hat reference which is always expected anyways.  However, alternative history and just world history in general has [...]]]></description>
			<content:encoded><![CDATA[<p>Here's something a little different.  Anyone that's known me personally for a while probably knows I have three main passions: music, technology, and researching conspiracy theories.  I get some flak for it occasionally, however it's usually just the typical tin foil hat reference which is always expected anyways.  However, alternative history and just world history in general has always fascinated me. Anyways, long story short, soon I'll be posting up some reviews of books and documentaries in addition to the usual programming stuff.  As always, feel free to post your comments, whatever your take.</p>
<p>As a quick preview, here are some of the books and documentaries I'll be reviewing soon:</p>
<h1>Documentary: Kubrick's Odyssey</h1>
<p><a href="http://www.youtube.com/watch?v=qySnL38JpOg&#038;fmt=18">http://www.youtube.com/watch?v=qySnL38JpOg</a></p>
<p>Created by <a href="http://jayweidner.com/">Jay Weidner</a> and produced by "Cubed Brick Productions" (get it, Kubrick?  Cubed-Brick? ha... anyways...) this documentary is extremely fascinating.  Without giving away all the best parts, it's about how Stanley Kubrick was offered the job to fake the Apollo 11 moon landings in a soundstage.  The argument is made that through photo analysis, the same exact technology used for the moon landing shots was later used for <a href="http://www.imdb.com/title/tt0062622/">2001:  A Space Odyssey</a>.  Specifically, the technology was a <a href="http://www.visual-memory.co.uk/sk/2001a/page2.html">3M fabric coated with very tiny mirrored beads of glass</a> which acted as a backdrop for the scenes, sort of like the first version of chromakey (aka "green screen").  Furthermore, this documentary tries to show that <a href="http://www.imdb.com/title/tt0081505/">The Shining</a> was Kubrick's attempt at exposing his involvement in one of the biggest coverups in American history.  Best of all, this documentary is just one in a series aimed at decoding all of Kubrick's work, up to and including the movie that "killed him," <a href="http://www.imdb.com/title/tt0120663/">Eyes Wide Shut</a>.</p>
<p><span id="more-1125"></span></p>
<h1>Book: A Terrible Mistake</h1>
<p><img class="alignnone size-medium wp-image-1133" src="http://producerism.com/wp-content/uploads/2012/02/terriblemistake-200x300.jpg" alt="" width="200" height="300" /></p>
<p>The whole title is a mouthful: <a href="http://www.amazon.com/Terrible-Mistake-Murder-Secret-Experiments/dp/0977795373">A Terrible Mistake: The Murder of Frank Olson and the CIA's Secret Cold War Experiments</a> by <a href="http://www.albarelli.net/">H.P. Albarelli Jr</a>.  This is one of the best reference books on the subject of <a href="http://en.wikipedia.org/wiki/Project_MKULTRA">MKULTRA</a> that I've read to date.  MKULTRA was a Top Secret CIA program originally started with the OSS's (precursor to CIA) search for a truth serum, and eventually evolved into a large umbrella with over 140 different subprojects.  The movie <a href="http://www.imdb.com/title/tt1234548/">The Men Who Stare at Goats</a> is based on an actual experiment called <a href="http://en.wikipedia.org/wiki/Project_Star_Gate">Project Stargate</a>, which was rumored to be an offshoot of MKULTRA.  A Terrible Mistake revolves around the death of a chemist located at Ft. Detrick in Maryland, that was dosed with LSD and then assassinated by a CIA agent.</p>
<h1>Book: Sinister Forces Trilogy</h1>
<p><img class="alignnone size-medium wp-image-1135" title="" src="http://producerism.com/wp-content/uploads/2012/02/1717434-L-192x300.jpg" alt="" width="192" height="300" /><img class="alignnone size-medium wp-image-1136" title="" src="http://producerism.com/wp-content/uploads/2012/02/sinister-forces-a-warm-gun-grimoire-american-political-peter-levenda-hardcover-cover-art-198x300.jpg" alt="" width="198" height="300" /><img class="alignnone size-medium wp-image-1137" title="" src="http://producerism.com/wp-content/uploads/2012/02/741024-L-199x300.jpg" alt="" width="199" height="300" /></p>
<p>This is an extremely detailed trilogy by <a href="http://en.wikipedia.org/wiki/Peter_Levenda">Peter Levenda</a>.  It's hard to wrap it up in a few sentences, but I'll do my best.  Levenda traces the roots of American politics, crime, and culture all the way back to the beginnings of human history.  This book covers stories from ancient Egypt, Knights Templar, Rosicrucians, Arawak natives, Salem witch trials, all of the world wars, all the way to Jim Jones, Lee Harvey Oswald, Nixon, and Charles Manson.  While this sounds like a huge range of unrelated groups and people, the entire focus of Sinister Forces is to tie these things together.  It really is a fascinating read.</p>
<h1>And more!</h1>
<p>For the record, I'm not very interested in alien abductions and UFOs, although I am quite interested about our ancestors' perspective on the stars, like the Dogon tribe's ancient knowledge of Sirius.  Most of the books I like reading are more about industry (oil and railroad barons), military and CIA operations (MKULTRA, Iran/Contra, etc.), secret societies (Freemasons, Adam Weishaupt's Bavarian Illuminati, "The Finders", etc.), and next-level weapons (HAARP, electromagnetic mind control, etc.).  In fact, the subject of mind control is of particular interest to me, as there are so many parallels to software engineering, not to sound creepy about it.</p>
<p>Hopefully some of you will find this stuff interesting.  If not, don't pay these posts any mind as I will be mainly focusing on code, tutorials, and other tech related stuff as I usually do.</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/conspiracy-theory-reviews/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Top 10 Tools, Tips, and Tricks for Corona SDK</title>
		<link>http://producerism.com/blog/top-10-tools-tips-and-tricks-for-corona-sdk-on-windows/</link>
		<comments>http://producerism.com/blog/top-10-tools-tips-and-tricks-for-corona-sdk-on-windows/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 23:13:51 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=1103</guid>
		<description><![CDATA[This post will cover some extremely useful third party tools (both free and paid) for Corona developers (specifically on Windows). Since starting with Corona SDK in 2011, I have really taken a liking to it. It hasn't replaced my other solutions yet , and I'm not sure that it ever will.. but truth is, it [...]]]></description>
			<content:encoded><![CDATA[<p>This post will cover some extremely useful third party tools (both free and paid) for Corona developers (specifically on Windows).</p>
<p>Since starting with Corona SDK in 2011, I have really taken a liking to it. It hasn't replaced my other solutions yet , and I'm not sure that it ever will.. but truth is, it doesn't have to replace anything. Corona seems to be in a good niche all to it's self, despite the pugilistic attitude towards Adobe's Flash/AIR/etc. Unlike Flash however, which has a robust IDE and large suite of complimentary applications (Photoshop, After Effects, Illustrator, etc.) Corona is bare-bones, really just an API bundled with a simulator and compiler. Once you get comfortable with the basics of Corona and are ready to dive in a bit deeper and make your workflow easier, here are some great tools:</p>
<h1>Software</h1>
<p>Various software that can save time and really help out specifically with Corona development.</p>
<h2>1. TexturePacker</h2>
<p><em>(<a href="http://www.texturepacker.com/">texturepacker.com</a> - free version available, Pro: $24.95)</em></p>
<p>TexturePacker is essential for creating spritesheets in Corona (it also exports to Unity3D, css, json, cocos2d and others).  To put it simply, TexturePacker allows you to drag and drop a folder full of images (swf, png, jpg, bmp) and automatically create a spritesheet / tilesheet image, and an exported program specific template.  There are quite a number of options to set, such as layout algorithms, padding, trimming transparency, and a host of other optimizations.  Personally, I found this useful when creating large spritesheets of animated assets - for example, the sheet below:</p>
<p><img class="alignnone size-full wp-image-1108" title="TexturePacker" src="http://producerism.com/wp-content/uploads/2012/02/gramophone.tps_2012-02-25_18-01-331.png" alt="" width="800" height="517" /></p>
<p><strong>Final Thoughts:</strong>  If you need to create lots of spritesheets, the $25 spent on this program will repay itself after the first hour or two you save yourself in time and frustration.  I cannot recommend this program enough to anyone creating sprite-based games in Corona, or any other program for that matter.</p>
<p><span id="more-1103"></span></p>
<h2>2. PhysicsEditor</h2>
<p><em>(<a href="http://www.physicseditor.de/">physicseditor.de</a> - Paid: $19.95)</em></p>
<p>Made by the same developer as TexturePacker, this tool is used to automatically create physics objects from image files that have transparency.  You simply drag and drop an image into the program, and trace it yourself or use the auto-tracer.  You can set physics attributes (density, friction, etc.) for each object, and even collision filtering.  After you are done setting all the shapes and parameters, it outputs all of the physics data to Corona SDK format (along with many other formats, including QuickBox2D for AS3/Flash, Box2D, and more).</p>
<p><img class="alignnone size-full wp-image-1109" title="PhysicsEditor" src="http://producerism.com/wp-content/uploads/2012/02/kitchen.pes_2012-02-25_18-05-14.png" alt="" width="838" height="672" /></p>
<p>Here is a screenshot of the automatic tracer, which will outline your object using the transparency in the image.  This features saves lots of time.</p>
<p><img class="alignnone size-full wp-image-1110" title="PhysicsEditor Tracer" src="http://producerism.com/wp-content/uploads/2012/02/Tracer_2012-02-25_18-05-28.png" alt="" width="685" height="484" /></p>
<p><strong>Final Thoughts:</strong> This program is another must-have for anyone creating physics-based games.  There are a few other solutions out there (some even free) but I've found this to be the easiest to use, and the only one which exports into various formats easily.  This program has saved me countless hours of tedious work, and will do the same for you.</p>
<p>&nbsp;</p>
<h2>3. JetBrains IDEA</h2>
<p><em>(<a href="http://www.jetbrains.com/idea/">jetbrains.com/idea</a> - Free)</em></p>
<p>One of the very best IDEs for programming in Lua (and Corona SDK) for Windows.  It supports auto-completion, code hinting, syntax coloring, all sorts of awesome features.  I use other JetBrains software (PhpStorm) as well, so it felt very natural to me.  The layout and feature set is very similar to NetBeans or Eclipse.  Since the various features and setup is a bit more complex, take some time and read over the tutorial I wrote on <a href="http://producerism.com/blog/how-to-develop-in-corona-sdk-on-windows/">Corona SDK development on Windows</a>, where you can get a better idea about... err, IDEA.</p>
<p><img class="alignnone size-full wp-image-851" title="corona_project_files" src="http://producerism.com/wp-content/uploads/2011/05/corona_project_files1.jpg" alt="" width="650" height="405" /></p>
<p><strong>Final Thoughts:</strong> In my opinion, there really aren't many other options out there that can compare with IDEA for Corona developers on Windows - especially considering the price tag (free).  If you're on Windows and not using IDEA for Corona development, you're in for a real treat!</p>
<p><strong>Update (05/09/2012):</strong>  There is a new solution made specifically for Corona SDK developers, <a href="http://www.mydevelopersgames.com/CIDER/">Corona Cider by M.Y. Developers</a>.  At the launch price ($29), it's a steal.  I have not been using it as much as IDEA yet, but I can see it becoming my primary Corona IDE with some more polish and features.</p>
<p>&nbsp;</p>
<h1>Third Party Libraries</h1>
<p>Some Corona code libraries which save time and add some great features.</p>
<h2>4. TextCandy</h2>
<p><em>(<a href="http://www.x-pressive.com/TextCandy_Corona/features.html">x-pressive.com/TextCandy_Corona</a> - Paid: ~$54)</em></p>
<p>Another common element of game development are bitmap fonts.  Even if you aren't creating games, using custom fonts can be a huge hassle for mobile devices.  By using TextCandy, you can add support for custom fonts easily, along with a very long list of additional features for animation of text.  The developers claim that it's not meant for text-heavy applications, more intended for animated text or other special treatment.  For game development, this is an incredible tool.  It also works very nicely with TexturePacker, for creating your own custom bitmap fonts.  The code is very clean and optimized for Corona projects.  It's officially supported on the Corona SDK forums, and is actively maintained.</p>
<p><a href="http://www.youtube.com/watch?v=AjrWRWc0ivg">http://www.youtube.com/watch?v=AjrWRWc0ivg</a></p>
<p><strong>Final Thoughts:</strong> If you need animated text or custom bitmap fonts, this is worth every penny.  Note: If you buy TextCandy, you can purchase ParticleCandy for 50% off.</p>
<p>&nbsp;</p>
<h2>5. ParticleCandy</h2>
<p><em>(<a href="http://www.x-pressive.com/ParticleCandy_Corona/features.html">x-pressive.com/ParticleCandy_Corona</a> - Paid: ~$54)</em></p>
<p>From the same developer as TextCandy, this as you can gather from the name, is a particle engine for Corona.  Originally based on Blitz3D (another game development solution), this is a light-weight and high performance library that supports sprite sheets, texture atlases, unlimited emitters, emission shapes, scaling, sounds, particle types, and too many other features to list.  Simple answer to this one is, if you need particles in your Corona project, and don't have the time, knowledge, or means to create your own particle engine, then this will be the best (and most impressive) $55 you can spend for an immediate solution that looks and works great.  The level of customization for this library is ridiculous, and I can't recommend it enough.</p>
<p><a href="http://www.youtube.com/watch?v=kq4eFVOvr0Q">http://www.youtube.com/watch?v=kq4eFVOvr0Q</a></p>
<p><strong>Final Thoughts:</strong> If you need animated text or custom bitmap fonts, this is worth every penny.  Note: If you buy TextCandy, you can purchase ParticleCandy for 50% off.</p>
<p>&nbsp;</p>
<h2>6. Lime (beta)</h2>
<p><em>(<a href="http://justaddli.me/">justaddli.me</a> - Beta: $27, Final: $54 )</em></p>
<p>This is a library that has so many features to make creating tile-based games easier, that it's hard to not recommend it.  <em>Except for one thing</em>: <strong>performance</strong>.  While this library offers a long list of enhancements (not the least of which are tile support, camera control, animated tiles, map loading, etc.), unfortunately a lot of those features are negated due to how poorly tile-based games perform using Corona in general.  This is not necessarily a fault of the Lime library.  In fact, when using Lime in the Windows / OSX simulator, everything runs very smoothly.  Only when you build to device to the issues start to become present (especially on Android devices, which are generally slower than iOS when using Corona).  There are a number of projects already released and fore sale using Lime, so it's not worthless by any stretch - however it's not the simple solution it seems to be, since there is quite a bit of optimization you have to do which can cancel out any time saved with Lime.</p>
<p><img class="alignnone size-full wp-image-1111" title="Lime - For Corona" src="http://producerism.com/wp-content/uploads/2012/02/Lime-For-Corona-®-iOS-Android-SDK-Google-Chrome_2012-02-25_18-11-50.png" alt="" width="832" height="487" /></p>
<p><strong>Final Thoughts: </strong>Since this isn't exactly the fault of Lime as much as it is the way Corona handles display objects (no support for blitting) it's hard to fault the developer.  However it also makes it hard to recommend, even at the discounted "beta" price of $27.</p>
<p>&nbsp;</p>
<h2>7. Crawl Space Corona SDK Library</h2>
<p><em>(<a href="http://www.crawlspacegames.com/crawl-space-corona-sdk-library">crawlspacegames.com/crawl-space-corona-sdk-library</a> - Free)</em></p>
<p>I d haven't had a lot of time to play with it, but this library should be compatible with the most recent builds of Corona (as of 2/25/2012) and adds lots of great features including fadeIn() and fadeOut() helper methods, timer managers, loading/saving data, music managers with fading, etc.</p>
<p><strong>Final Thoughts: </strong>Since I haven't had a lot of time to experiment, the jury is still out on this.  However since it's free, it's well worth the time to check it out!</p>
<p>&nbsp;</p>
<h2>8. Simple Analog Stick Module (lib_analog_stick)</h2>
<p><em>(<a href="http://developer.anscamobile.com/code/simple-analog-stick-joystick-module">developer.anscamobile.com/code/simple-analog-stick-joystick-module</a> - Free)</em></p>
<p>Here's a free library, since the rest all cost money.  This is a really useful virtual joystick module which allows you to create as many touch-screen joysticks in your game as you want.  It supports functions like getDistance, getPercent, and getAngle for figuring out how the user is interacting with each of the sticks.  It also has a very easy way to move an object with a stick, by simply calling Stick:move(player, 5.0) where player is the object to be moved, and 5.0 is the speed.  For prototyping, it's so easy to just add this to a project and get going.</p>
<p><strong><strong>Final Thoughts:</strong></strong> For the price, you'd be insane not to check this out!</p>
<p>&nbsp;</p>
<h1>Debugging Tools</h1>
<p>Tools to make your life easier during development and debugging.</p>
<h2>9. Corona Ultimote</h2>
<p><em>(<a href="http://www.mydevelopersgames.com/site/corona-ultimote-2/">mydevelopersgames.com</a> - Paid: $16.99)</em></p>
<p>This is an Android and iOS app (you get both after paying), which allows you to stream device messages (like multitouch, GPS, accelerometer, etc.) to the Corona Simulator when developing and testing.  Instead of building to the device each time you want to test an app, you can do it live in development.  The process isn't perfect, however it does save lots of time in building and testing, so for that alone it's worth the price of admission.  Another cool feature is that Ultimote will actually stream images to the device as well, so you know where to touch the screen and etc.  Again, this tool seems like it's a bit unpolished and under development, however it also seems to be the only solution for Corona SDK that supports both Android and iOS.</p>
<p><a href="http://www.youtube.com/watch?v=fZBjw_8100o">http://www.youtube.com/watch?v=fZBjw_8100o</a></p>
<p><strong>Final Thoughts:</strong> If you are developing anything that relies on physical sensors or input (orientation, multi-touch, tilt, compass, etc.) this is one of the best tools you can get.  Since it includes both iOS and Android apps (along with a Corona Lua script), this really is one of the only options out there anyways.</p>
<p>&nbsp;</p>
<h2>10. Corona Profiler</h2>
<p><em>(<a href="http://www.mydevelopersgames.com/site/">mydevelopersgames.com</a> - Paid: $9.99)</em></p>
<p>Another product from M.Y. Developers, who also make Ultimote.  After your app or game is mostly done, then begins the real hard part: testing, debugging, and optimizing.  Unfortunately, one of the biggest issues with Corona development is the lack of a great debugger.  The Corona Profiler helps bridge that gap a little by creating a detailed interactive report, which allows you to trace where all the memory and processing is going during your app execution.  It's very helpful in ferreting out memory leaks or singling out functions that need to be optimized or broken into smaller steps.  Unlike the other tools mentioned so far, this doesn't automatically make your project better, but it does make your life easier when you want your app to run faster, but don't know where to start.</p>
<p><a href="http://www.youtube.com/watch?v=ft2fObkahN4">http://www.youtube.com/watch?v=ft2fObkahN4</a></p>
<p><strong>Final Thoughts:</strong> Very much worth the $10 it costs in every way.  Typically, the debugging and optimization steps in game development take the longest.  Any tool out there which can make this any easier is worth its weight in gold.  But since this is an intangible product, let's just say it ways at least $10 in gold and worth every cent.</p>
<p>&nbsp;</p>
<h2>Bonus: Photoshop</h2>
<p><em>(<a href="http://www.photoshop.com/">photoshop.com</a> - Paid: $699)</em></p>
<p>This shouldn't be a huge shocker, but Photoshop (or any other image editing program) is essential to create the graphics you need.  Also, since the price tag is the better half of $1,000 it may not be a viable solution to many readers.  In that case there are many other options out there which are free or at least much cheaper.  I just want to point out a big caveat for anyone using photoshop for Corona Development.  <strong>IMPORTANT: Save all your graphics as PNG and DO NOT use "Save for Web!"</strong>  I cannot stress this enough.  Saving your graphics with "save for web" can cause a long list of unexpected and inconsistent issues, specifically with iOS.  I spent more time than I should have figuring out the hard way, that the PNG files I was using on Android in Windows, didn't work on the OSX simulator and consequently, anything I exported (iPhone, iPad, Android, etc.) didn't load properly either.  Certain PNG assets would simply show up as all white.  After a few bug reports submitted, and trying various PNG tools I realized the problem went away after I stopped saving for web.  Save yourself some time and learn from my mistakes!</p>
<p><strong>Final Thoughts:</strong> Use whatever you want.  Just be careful on how you export your images, and be sure to test across platforms and devices.</p>
<p>&nbsp;</p>
<h1>Conclusion</h1>
<p>To be up-front, I have not been paid or solicited in any way to review any of these products. Also, I realize that the tools that work for me may not work for you (or vice versa).  There are also a number of products out there that I haven't evaluated yet (e.g. <a href="http://coronaprojectmanager.com/">Corona Project Manager</a>, <a href="http://www.loqheart.com/spriteloq/">Spriteloq</a>, <a href="http://www.kwiksher.com/">Kwik</a>, etc.)  The main reason I haven't checked these out, is because they aren't free, and I haven't had an immediate need for any of them.. yet.  Spriteloq seems to serve a similar purpose as TexturePacker, except it exports animated SWFs to spritesheets.  Corona Project Manager is a little like an IDE but lacking in robust features although it caters specifically to Corona projects.  Finally Kwik seems like a really great plugin for photoshop users - essentially allows you to create animations and interactive apps within photoshop and export to Corona.</p>
<p>If you have any questions, problems, or suggestions regarding anything mentioned above, please leave a comment!</p>
<p>P.S. Allow me to apologize about any abundant alliterations in the title.</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/top-10-tools-tips-and-tricks-for-corona-sdk-on-windows/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Working on 2 new Corona SDK Games</title>
		<link>http://producerism.com/blog/working-on-2-new-corona-sdk-games/</link>
		<comments>http://producerism.com/blog/working-on-2-new-corona-sdk-games/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 23:54:53 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=1089</guid>
		<description><![CDATA[After attending the first Orlando Corona SDK Meetup this this week, I was really inspired by Ansca Mobile's  Carlos Icaza to begin cranking out games.  In fact, I've already started on my New Year's resolution - create and publish at least 4 (mobile) games next year.  After lots of consideration and testing, I'm pretty much set [...]]]></description>
			<content:encoded><![CDATA[<p>After attending the first Orlando Corona SDK Meetup this this week, I was really inspired by Ansca Mobile's  <a href="http://www.carlosicaza.com">Carlos Icaza</a> to begin cranking out games.  In fact, I've already started on my New Year's resolution - create and publish at least 4 (mobile) games next year.  After lots of consideration and testing, I'm pretty much set on using Corona for all of them.  I'm still holding out lots of hope for Adobe AIR, and would love to create games for mobile with Flixel and FlashPunk - but I just can't get the performance I'm looking for (yet).</p>
<p>With that said, the first game is actually part of a larger project I'm working on, but the general game design is a bit like a fast-paced Gun.Smoke:</p>
<p><a href="http://www.youtube.com/watch?v=MzPlGJ85jCM">http://www.youtube.com/watch?v=MzPlGJ85jCM</a></p>
<p>The biggest things I'm struggling with now are the controls and orientation.  Currently, there is a virtual joystick in the lower right corner to move the player.  I've tried just using the touch screen, but then your finger covers up more real estate when playing.  The real estate issue is the same reason I took away the left/right fire buttons on the left.  I'm also deciding on whether or not to allow the player to shoot left and right, or restrict the player's attack to straight up (like 1942).</p>
<p><a href="http://www.youtube.com/watch?v=4eK7K3xtVms&#038;fmt=18">http://www.youtube.com/watch?v=4eK7K3xtVms</a></p>
<p>The funny this is that when creating similar games in AIR, I would have still been messing around with compiling and optimizing, so worrying about game design and UI issues is a welcomed task.  On the other side of that coin, when I needed to make a wave (level) editor for my game the first thing I thought of was Flash/AIR , which worked out great.  With the wave editor, I'm able to start putting together some strategic layouts.  There's no real AI for any of the enemies yet, but I do plan on adding that soon too.</p>
<p style="text-align: center;"><a href="http://producerism.com/wp-content/uploads/2011/12/JekyllIslandLevelDesigner.swf_2011-12-22_18-40-39.png"><img class="aligncenter  wp-image-1094" title="JekyllIslandLevelDesigner.swf_2011-12-22_18-40-39" src="http://producerism.com/wp-content/uploads/2011/12/JekyllIslandLevelDesigner.swf_2011-12-22_18-40-39.png" alt="" width="797" height="477" /></a></p>
<p>Since the top-down shooter project is probably going to take at least a few more months, I've also started on another game.  While it's starting out as a Peggle Clone (which I'll probably use to write a detailed Corona SDK tutorial), I've got a few ideas in mind of where I'd like to take it eventually.  I'm hoping to release this one as soon as March, and continually update and improve upon it.  For a quick preview of where I'm at after 6 hours, here's a video:</p>
<p><a href="http://www.youtube.com/watch?v=gWjiUPssHSQ&#038;fmt=18">http://www.youtube.com/watch?v=gWjiUPssHSQ</a></p>
<p>Finally, it's been a while since I last posted - and due to the holidays, it may be another while until the next one.  So just to throw out there... I've also been working a LOT with AIR/Android development, along with using PhoneGap and jQuery Mobile with a few projects.</p>
<p>I realize that so far this blog might seem a bit Flash/Corona biased, but there are so many other cool projects and technologies I've been working with, that I can't wait to write about soon.  Thanks to all the new readers that have been visiting, and feel free to drop me a message/comment about any tutorials or articles you'd like to see.</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/working-on-2-new-corona-sdk-games/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Corona SDK vs AIR 3 for mobile games</title>
		<link>http://producerism.com/blog/corona-sdk-vs-air-3-for-mobile-games/</link>
		<comments>http://producerism.com/blog/corona-sdk-vs-air-3-for-mobile-games/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 13:53:50 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=1068</guid>
		<description><![CDATA[Yesterday at Adobe MAX, Adobe announced a major upgrade with AIR 3.  Along with a host of improvements and new features, the main ones that caught my eye included "new architecture for high-performance 2D/3D GPU accelaration," and improved mobile support.  Actually, those two items combined highlight my biggest concern with AIR - performance. For making [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-1081" title="corona-vs-air-3" src="http://producerism.com/wp-content/uploads/2011/10/corona-vs-air-3.png" alt="" width="676" height="190" /></p>
<p>Yesterday at Adobe MAX, Adobe announced a major upgrade with <a href="http://www.adobe.com/products/air.html">AIR 3</a>.  Along with a host of improvements and new features, the main ones that caught my eye included "new architecture for high-performance 2D/3D GPU accelaration," and improved mobile support.  Actually, those two items combined highlight my biggest concern with AIR - performance.</p>
<p>For making productivity or utility apps, AIR is a great choice (depending on the level of control you need over native functions).  However for <strong><em>mobile</em></strong> apps that involve lots of movement and listeners (i.e. games), it hasn't been as much of an option.  The performance issues alone <a href="http://producerism.com/blog/how-to-develop-in-corona-sdk-on-windows/">turned my interest to Corona SDK</a>, since it allows developers to target multiple devices with the same code and assets (and maintain performance <a href="http://producerism.com/blog/where-corona-sdk-falls-flat/">to an extent</a>).<span id="more-1068"></span></p>
<p>However, the latest update to AIR seems to be a HUGE step in the right direction.  Without changing any of my actionscript at all, and by simply updating my mobile devices (EVO 4G, Nook Color) to AIR 3, I had an instant performance increase.  To get a better idea of the actual performance increase, I need to add some FPS/memory logs and run them again on the older and newer versions of AIR.  However I can say without a doubt, the performance increase from AIR 2.7.1 to AIR 3 was substantial enough to get excited about.</p>
<p>The Stage 3D rendering is still only supported on personal computers and TVs (oh yeah, the other big announcement was the integration of AIR into TV sets) but should be coming to mobile/tablets soon.  That's not really a big issue for me, since I haven't ventured much into 3D mobile apps outside of a few Unity tutorials.  However, all of this is really good news for Flash and ActionScript developers.  Not only is Adobe pushing for more and more device compatibility, but they are also focusing on many performance issues that seemed to have taken a backseat over the years.</p>
<h2>Corona SDK vs AIR?</h2>
<p>To me, the Corona vs AIR debate was largely centered around device compatibility and performance.  The simplified use of Lua that Corona uses certainly makes life easier, but if performance is no longer an issue with AIR, then it's more like Corona SDK vs <a href="http://flashpunk.net/">FlashPunk</a>, or Corona SDK vs <a href="http://flixel.org/">Flixel</a>. I'm assuming Corona still does outperform AIR, and  this isn't to say that Corona won't continue to outperform AIR as time goes on.  However, it looks like Adobe is making lots of progress and the gap is starting to close.  <a href="http://joshblog.net/2011/05/13/adventures-with-corona-part-1-what-corona-offers-thats-better-than-adobe-air/">I'm not the only one</a> that's constantly torn between the too either.</p>
<p><img class="alignnone size-full wp-image-1082" title="corona-vs-the-world" src="http://producerism.com/wp-content/uploads/2011/10/corona-vs-the-world.png" alt="" width="676" height="190" /></p>
<p>Of course, I became a subscribed member of Corona SDK the <em>day before</em> this huge announcement, and now own a license for both Android and iOS development... so I'm still just getting started with Corona, and don't intend to stop.  However, since I prototype most of my games in Flash first anyways, I'm looking forward to perhaps skipping the Corona porting process altogether for certain future projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/corona-sdk-vs-air-3-for-mobile-games/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Building the Perfect HTPC / Media Server</title>
		<link>http://producerism.com/blog/building-the-perfect-htpc-media-server/</link>
		<comments>http://producerism.com/blog/building-the-perfect-htpc-media-server/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 16:47:02 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=998</guid>
		<description><![CDATA[This post is a break from the normal topic of programming, but has the same level of geekery/technobabble that you have come to expect from my blog.  Over the past few years, media usage and needs have been changing/evolving to the point where some people almost completely rid of physical CDs, DVDs, even books.  There [...]]]></description>
			<content:encoded><![CDATA[<p>This post is a break from the normal topic of programming, but has the same level of geekery/technobabble that you have come to expect from my blog.  Over the past few years, media usage and needs have been changing/evolving to the point where some people almost completely rid of physical CDs, DVDs, even books.  There is also a "<a href="http://lmgtfy.com/?q=cut+the+cord">cut the cord</a>" movement that emphasizes cutting out any services that you don't make full use of (e.g. cable TV), and favor anything which makes media consumption more convenient.</p>
<blockquote><p><strong>Here is a quick description of the perfect HTPC / Media Server:</strong> Something that can automatically download, repair, extract, gather information on, rename, sort, and play back movies, tv shows, albums, ebooks, games, and even comic books - while making all of the content remotely accessible via browser, mobile-devices, etc.  Oh yeah, and it should be able to run 24/7 while using less energy than a (incandescent) light bulb.</p></blockquote>
<p>While there are a million and a half ways to setup an HTPC (Home Theater PC) / Media Server, I'm pretty satisfied with my current setup, so I thought I would share.  In a nutshell, I built a mini-ITX system (for less than $400, which runs at less than 50W) running a combination of <a href="http://sabnzbd.org/">Sabnzbd</a>, <a href="http://sickbeard.com/">Sick Beard</a>, <a href="http://couchpotatoapp.com/">Couchpotato</a>, <a href="http://www.subsonic.org/pages/index.jsp">Subsonic</a>, <a href="http://www.tightvnc.com/">VNC</a>, <a href="http://xbmc.org/">XBMC</a>,<a href="http://maximusarcade.com/"> Maximus Arcade</a> and a few other small utilities.  With an exception to Maximus Arcade, all of this can be setup using any hardware/OS combination (Windows, OSX, Linux) that supports Java and Python.</p>
<p><img class="alignnone size-full wp-image-1005" title="ultimatehtpc" src="http://producerism.com/wp-content/uploads/2011/09/ultimatehtpc.jpg" alt="" width="743" height="350" /></p>
<p><span id="more-998"></span></p>
<h1>Defining Needs / Requirements</h1>
<p>Since HTPC / Media Server is slightly vague, here are the specific features I wanted:</p>
<p><strong>Automated Downloading of Movies / TV - </strong>Specifically, a way to simulate the functionality of a DVR, without any need for cable TV.</p>
<p><strong>Remote Accessibility - </strong>Being able to access/share my media library from the road, work, cellphone, wherever - and only using VNC as a last resort.</p>
<p><strong>Low Power Usage</strong> - I wanted to build a machine that could be left on 24/7, without concerns about electric bills or overheating.</p>
<p><strong>Easy to add media, or send links for downloading - </strong>Sometimes you think of a show/movie/album you want when away from your computer (at a party, on the road, dinner conversation, etc.)  Having an easy way to add items you want remotely is a very attractive feature.</p>
<p><strong>Ability to Play Emulators and ROMs</strong> - For me, no HTPC would be complete without the ability to play old console (NES, Genesis, PSX, etc.) games.</p>
<h1>From Cable &amp; DVR, to Usenet &amp; Sabnzbd</h1>
<p><img class="alignnone size-full wp-image-1006" title="saboverdvr" src="http://producerism.com/wp-content/uploads/2011/09/saboverdvr.jpg" alt="" width="743" height="125" /></p>
<p>It's funny how technology can change behavior over time.  Back when I had cable, and before I had a DVR, there were only a few ways to catch a movie/tv show - either plan on being home to watch the show/movie when it aired on TV, or rent a DVD / stream from Netflix (assuming the video you want is available, and not too recent).  Then, after getting a DVR a few years ago, planning my schedule around when a show came on was out the window.  It was a liberating feeling, and let me catch up on shows when I had the time to do so.  Not to mention, being able to fast-forward through commercials was a bonus.</p>
<p>After a while though, the novelty of a DVR wore off, especially as the rate and taxes for Cable TV continued to rise.  Not just that, but if you ever look into <a href="http://consumerist.com/2010/03/list-of-subscriber-fees-shows-what-you-pay-for-channels-you-hate.html">subscriber fees associated with cable</a>, you'll notice that the rates for the various channels is far from equal (e.g. ESPN costs around $4/month, while the Science Channel costs only $0.06/month).  So unless you are a heavy sports fanatic, chances are over half of your cable bill is going to channels you'll never watch.  I definitely fall into that category, and the <a href="http://consumerist.com/2010/03/list-of-subscriber-fees-shows-what-you-pay-for-channels-you-hate.html">linked Consumerist article</a> played a huge factor in motivating me to look for other solutions.</p>
<h1>Newsgroups</h1>
<p><img class="alignnone size-full wp-image-1007" title="usenet_providers" src="http://producerism.com/wp-content/uploads/2011/09/usenet_providers.jpg" alt="" width="743" height="125" /></p>
<p>Enter <a href="http://www.slyck.com/ng.php">Newsgroups</a>.  Most netizens are familiar with direct downloading (e.g. forums, ftp sites, rapidshare, filesonic, hotfile, etc.) or p2p (limewire, torrents, etc.).  In fact, just about anyone who has downloaded a digital movie or album online outside of iTunes, has probably done so via direct downloads or p2p.  While those are easy and popular options, the reliability and quality of the files, and most importantly - security of the process, are all very questionable.  Download sites keep track of IPs, and are riddled with misleading links and malware scripts.  Torrents have slightly better quality control, but they are also probably the biggest source of copyright infringement lawsuits.  This is because by design, when you download a torrent you are also uploading that torrent to the rest of the world (making you a source for potentially pirated media).</p>
<p>While newsgroups don't completely solve all of those issues, they get close and have other advantages.  Most people don't even realize they already have newsgroup access with their current internet provider.  Of course, the free access provided by ISPs is very limited, and <strong><em>not</em> anonymous/secure</strong>, so this is where a premium usenet provider comes into play.</p>
<p>Premium newsgroup access is typically secure and much more "anonymous" than any other method of downloading (depending on who you get newsgroup access through, and your router/network setup).  The other big advantage is that most usenet providers allow you to download as fast as your connection will allow (as opposed to torrents, which are limited to the speed of your peers).</p>
<p>There is an inherent learning curve when dealing with newsgroups, and user-friendly clients have only started becoming more and more refined over the past few years.  At some point, a friend pointed me towards an automated usenet downloading solution called <a href="http://sabnzbd.org/">Sabnzbd</a>.  This actually takes lots of the "manual labor" out of usenet.</p>
<h2>Costs?</h2>
<p>As you might have assumed from the name, "premium" newsgroup access is not free.  It ranges from less than $10 per month to over $30.  For the best of the best, I would suggest <a href="http://www.giganews.com/?c=gn548475">Giganews</a>, which ranges from $5 to $35 per month.  Second to that, is <a href="http://www.supernews.com/?i=ZcvnpGyA4ww=">Supernews</a>, which is run by the same company.  Supernews offers a single unlimited service, for a flat rate of $12 per month.  There are lots of other options, such as UsenetServer and Astraweb.  Both have good reviews and are perfectly decent alternatives.</p>
<p>So what is the actual cost of all this?  Well the average digital cable TV bill is around $75 per month.  Add internet access, premium channels and a DVR, and the cost easily rises to over $100.  That's not even taking into consideration subscriptions to other services like Netflix and Hulu.  Similarly, the average high-speed internet connection bill is around $75 per month.  By adding another $10 for usenet access, you can have so much more, for so much less.  $85 per month is about the top-end of what you would pay for an unlimited selection of tv shows, movies, music, games, etc.  There are some other small costs here and there too, such as an <a href="http://nzbmatrix.com/">NZBMatrix</a> subscription for $12 (for 5 years).</p>
<h1>Introduction to Sabnzbd</h1>
<p><img class="alignnone size-full wp-image-1009" title="sabnzbd-screenshot" src="http://producerism.com/wp-content/uploads/2011/09/sabnzbd-screenshot.jpg" alt="" width="743" height="200" /></p>
<p>Sabnzbd (which stands for <strong>SAB nzb d</strong>aemon) is basically a python service which runs in the background, and makes monitoring, downloading and uploading files extremely easy.  The entire app runs as a webservice, and is accessible via the browser (e.g. "http://localhost:8080").  Just like a<em> .torrent</em> file is simply an indexed list of links, newsgroup binaries have indexed links saved as <em>.nzb</em> files.  Normally when using an NZB file, your newsgroup client (e.g. Newsbin Pro, Unison, etc.) will find all of the "parts" in the NZB, and then download them.  Depending on the newsgroup client features, the program may also assemble file parts, repair them (using .par2 files or recovery records), extract them (unzip, unrar, etc.) and even delete the original files (the leftover .rar, .zip, etc.)  Truth is, since using Sabnzbd, I don't have a need for usenet clients anymore.  Sabnzbd will do all of these things (assemble, repair, extract, delete) and much more (such as renaming, sorting, etc.)</p>
<h2>Getting Sabnzbd to download stuff...</h2>
<p>So you have sabnzbd installed and setup.  How do you get it to actually download something?  That's actually the easy part!  There are three main ways to send files for sabnzbd to download.  First, you can just click the "add nzb" button at the top of the screen.  From there you simply upload an .nzb file directly, and sab does the rest.  The second way of sending nzb files to sab is via a "watched folder."  This is a folder somewhere on your system (e.g. "C:\downloads\nzb") that sabnzbd will constantly monitor for files.  As soon as it finds an .nzb file, it will add it to the list of items to download.  The third method is to setup an RSS feed through a site like <a href="http://nzbmatrix.com/">NZBMatrix</a>.  More on this in a later tutorial.  Those are the basic ways to get sabnzbd downloading... but that's just the tip of the iceburg.  The real power of sabnzbd comes into play when you pair it with other services.</p>
<h1>Introduction to Sick Beard</h1>
<p><img class="alignnone size-full wp-image-1010" title="sickbeard_screenshot" src="http://producerism.com/wp-content/uploads/2011/09/sickbeard_screenshot.jpg" alt="" width="743" height="250" /></p>
<p>As aforementioned, once you have sabnzbd running, you are pretty much good to go.  The caveat is that you will need to manually find NZB files to send sabnzbd, which is pretty inconvenient unless you already know what you want to download.  Sick Beard is basically the Usenet/Sabnzbd counterpart to a DVR, and like sabnzbd, it runs on Python, and comes with a web interface you access via browser (http://localhost:8081).  With Sick Beard, you simply enter a list of shows you would like to watch (either currently airing, or off the air) and it will automatically search for new episodes and send them to sabnzbd when found.  As you can see in the screenshot above, The series "FlashForward" and "Testees" are both ended (series was cancelled), however Sick Beard was able to find all of the episodes.  Likewise for "Through the Wormhole," which is still airing - all 17 episodes were found and downloaded (aka sent to sabnzbd to be downloaded).  You can also see that "Quality" can be set to either <strong>SD</strong> (standard), <strong>HD</strong> (720p, 1080p, etc.), <strong>Custom</strong> (I set custom to look for either SD or HD, and grab whatever it finds), or <strong>All</strong> (downloads anything it finds, regardless of quality).  There is also a convenient field for "Next Ep" which displays the next date an episode is expected to air.</p>
<h2>Adding Shows to be downloaded</h2>
<p>With a DVR, adding shows is fairly easy.  You can add a show by going into a menu and searching by name, or usually by just browsing the DVR Guide and clicking on the show.  With Sick Beard, it's just as easy.  You can either enter shows by searching (Sick Beard uses theTVDB.com for results) by name, or by searching through folders and extracting the shows from file names of  already-downloaded episodes.  This is a great feature for anyone that already has a library of tv shows that were found before using Sick Beard.</p>
<p><img class="alignnone size-full wp-image-1011" title="sickbeard-addshow" src="http://producerism.com/wp-content/uploads/2011/09/sickbeard-addshow.jpg" alt="" width="743" height="250" /></p>
<h2>The Show page, and downloading specific episodes</h2>
<p>Once a show is added, you can view the list of episodes and edit any show settings on the page that is created.  Here is an example for the TV show "<a href="http://thetvdb.com/?tab=series&amp;id=155201&amp;lid=7">Louie</a>"</p>
<p><img class="alignnone size-full wp-image-1012" title="sickbeard-showpage" src="http://producerism.com/wp-content/uploads/2011/09/sickbeard-showpage.jpg" alt="" width="743" height="250" /></p>
<p>As you can see, all of the settings along with some meta-data (grabbed from theTVDB.com) are displayed here, along with an "Edit" button to change the download folder, show name, quality, etc.  There are also quick links to each season in the top right, along with specials.  Below all of this is the list of actual episodes.  Here is a cropped screenshot of the Season 2 list:</p>
<p><img class="alignnone size-full wp-image-1013" title="sickbeard-episodes" src="http://producerism.com/wp-content/uploads/2011/09/sickbeard-louie.jpg" alt="" width="743" height="250" /></p>
<p>Again - Sick Beard takes the list of shows you have entered, and searches for any episodes marked as "unaired" or "wanted".  When the NZB file for an episode is found, it sends it to Sabnzbd and updates the status to "snatched."  Once Sabnzbd successfully repairs, assembles, and extracts the file, Sick Beard then gets a message to update the status again to "Downloaded."  The search button on the right of each episode is a quick way to download a specific one.  We'll move on now, since this isn't a Sick Beard tutorial, just a quick overview to give you an idea of what it does.</p>
<h1>Introduction to CouchPotato</h1>
<p>No DVR is complete if it can only download TV shows - there are also movies, documentaries, straight-to-video releases, and more.  The counterpart to Sick Beard (which keeps track of TV shows) is <a href="http://couchpotatoapp.com/">CouchPotato</a> (which keeps track of movies/documentaries).  As with both sabnzbd and Sick Beard, CouchPotato is a python script which comes with a web-interface you can access via browser.</p>
<p><img class="alignnone size-full wp-image-1014" title="couchpotato" src="http://producerism.com/wp-content/uploads/2011/09/couchpotato.jpg" alt="" width="743" height="250" /></p>
<p>Adding movies to the list is very easy, along with selecting the preferred quality.  CouchPotato uses a few sources including IMDB and <a href="http://www.themoviedb.org/">theMovieDB</a> for meta-data like release date, descriptions, ratings, poster, etc.  It checks for new releases every 12 hours (configurable) and when an NZB file is found, it gets sent off to sabnzbd for the heavy lifting.</p>
<h1>Introduction to Headphones</h1>
<p><a href="https://github.com/rembo10/headphones">Headphones</a> has a very similar layout to CouchPotato, and serves the same purpose, but for music.  You can enter the name or an artist, or a particular album you want - and it will periodically search for an NZB, and send it to sabnzbd if found.  Headphones is fairly new, and development is still in progress.  There are a few features that are not fully implemented, and the entire process / configuration isn't the easiest to figure out without a little bit of tweaking.  Also, moreso than video libraries, music libraries are notoriously difficult to organize, since there are so many variations of albums, and sources for music.  Not to mention the tagging and file naming conventions are all over the place.  For those reasons, Headphones freaks out a little bit when you try to import an existing library.  I assume that with time, this will become more polished.</p>
<p><img class="alignnone size-full wp-image-1037" title="headphones" src="http://producerism.com/wp-content/uploads/2011/09/headphones.jpg" alt="" width="640" height="267" /></p>
<h1>Other Automated Downloading Solutions</h1>
<p>So far all of these solutions have been centered around sabnzbd (and usenet) being the sole provider of media.  There are of course many other ways to automate the searching/downloading process.  I won't go into too much detail down these other routes, but I would highly recommend:</p>
<p><a href="http://www.utorrent.com/"><img class="alignnone size-full wp-image-1015" title="utorrent" src="http://producerism.com/wp-content/uploads/2011/09/utorrent.jpg" alt="" width="232" height="66" /></a></p>
<p>For downloading torrents,  <a href="http://www.utorrent.com/">uTorrent</a> (as of version 3.0) supports remote access, RSS feeds and a long list of other options.  It can also be setup to use a web interface, just like sabnzbd, Sick Beard, and couchpotato.</p>
<p><a href="http://jdownloader.org/"><img class="alignnone size-full wp-image-1017" title="jdownloader" src="http://producerism.com/wp-content/uploads/2011/09/jdownloader1.jpg" alt="" width="362" height="65" /></a></p>
<p>For downloading directly (web links, ftp, file-hosting sites like rapidshare, hotfile, etc.) <a href="http://jdownloader.org/">JDownloader</a> is one of the best apps out there.  It supports all sorts of cool features like scheduling, remote control, auto extraction, etc.  It supports premium accounts (rapidshare, hotfile, etc.) if you have them, and if not it will take care of the waiting process, redirections, and even has an anti-captcha module which will try to automatically answer any captcha challenges.</p>
<h1>The Home Theater part of HTPC</h1>
<p>With all of the media downloaded, the next step is to actually play the stuff!  For watching tv/movies, the two most popular cross-OS solutions are Boxee and XBMC.  Plesk is OSX only, and Windows Media Center is for PC only.</p>
<p><a href="http://www.boxee.tv/"><img class="alignnone size-full wp-image-1021" title="boxeelogo" src="http://producerism.com/wp-content/uploads/2011/09/boxeelogo.png" alt="" width="334" height="89" /></a></p>
<p>I have used Boxee in the past, and actually prefer it as an out-of-the-box solution.  Along with having a standalone unit, <del>Boxee is also being built directly into TVs now</del> - <a href="http://www.engadget.com/2011/09/08/viewsonic-abandons-plans-for-boxee-powered-tv/">nevermind, it seems as though that has been abandoned</a>.  In addition to playing back video and audio files, Boxee has built-in support for Hulu, Netflix, Pandora, and all sorts of other video sources (youtube, reddit, etc.)  There are plenty of skins and addons to explore with the least amount of setup.  The only reason I stopped using Boxee was due to some technical issues with video playback and hardware acceleration, along with a personal dislike of the way Boxee handles/buffers streaming media.</p>
<p><a href="http://xbmc.org/"><img class="alignnone size-full wp-image-1022" title="xbmclogo" src="http://producerism.com/wp-content/uploads/2011/09/xbmclogo.jpg" alt="" width="581" height="158" /></a></p>
<p>My preferred media app is XBMC (which stands for XBox Media Center, since it was originally designed to run on the original Microsoft XBox).  Like Boxee, it runs on Windows, OSX and Linux, and is highly extendable. Sick Beard also supports updating of the XBMC library whenever a new show is downloaded.  A small feature, but very nice to have.  There is less support for other media sources (e.g. Hulu, Netflix, etc.) without third party extensions (which don't work as well as Boxee's implementation).  I currently use XBMC because it does not have the technical issues I was experiencing with Boxee, and I prefer the additional levels of customization.</p>
<h1>Games</h1>
<p>XBMC and Boxee both have "Launcher" apps that can launch a game from within the interface, but they all seem a bit cumbersome.  Personally, I would rather use a gaming pc for playing modern games, and if playing games on an HTPC at all, would be via emulators and roms, or perhaps a service like <a href="http://www.onlive.com">OnLive</a>.  There are even specialized extensions for Boxee and XBMC to launch roms/emulators, but again they are a hassle to use.  This is where Maximus Arcade comes into play.</p>
<h1>Introduction to Maximus Arcade</h1>
<p><a href="http://maximusarcade.com"><img class="alignnone size-full wp-image-1023" title="maximus-logo" src="http://producerism.com/wp-content/uploads/2011/09/maximus-logo.jpg" alt="" width="740" height="97" /></a></p>
<p>Maximus Arcade is a Windows-only program and doesn't actually play ROMs by itself.  It's a front end for all sorts of emulators for systems like NES, Genesis, Playstation, SNES, MAME, Gameboy, N64, Gamecube, ScummVM, etc.  Anyone that plays a decent amount of emulators knows that there is usually a different program for each system, and sometimes even specific settings/programs for certain roms.  This is where Maximus really shines.  You can configure which emulators launch each type of ROM, and even fine tune the settings for each.  Maximus also hooks into <a href="http://emumovies.com/forums/index.php?/page/index.html">EmuMovies</a> to automatically download box art, instructions, descriptions, screenshots and even video previews for your ROMs.  Navigating is extremely simple, as you can see below:</p>
<p><img class="alignnone size-full wp-image-1025" title="maximus" src="http://producerism.com/wp-content/uploads/2011/09/maximus.jpg" alt="" width="640" height="267" /></p>
<p>It can take quite a while to configure Maximus Arcade (it took me an entire weekend) - since you need to download each of the emulators manually, then configure them one by one in the settings.  Once it's all setup though, this program is a dream to use.  It's very easy to navigate between ROMs and systems, and the level of customization is almost limitless.  Unlike the rest of the apps mentioned so far, this is not freeware or open-source.  It's a windows-only program that has a trial download, or a paid version for around $30.</p>
<h1>How About the Media Server?</h1>
<p>Great, you have a machine that can download and play media exactly how you want.  As long as you are in the same room as the computer, that is.  Making all of this accessible remotely (from work, on vacation, available to friends, from mobile devices, etc.) is the next step towards perfection of the ultimate HTPC/Media Server.  First, let's cover the obvious: streaming audio and video.  As long as you setup your home network (router, workgroups, "homegroups", etc.) correctly, you should already be able to access the files on your HTPC from other computers.  Both XBMC and Boxee will allow you to stream media from the computer, so there is no further setup required for that.  However, this only works within your home network (LAN).  If you want to watch a movie or listen to music from work or on the road, unless you have a ridiculously fast connection, there's no real way to stream.</p>
<p><a href="http://www.subsonic.org"><img class="alignnone size-full wp-image-1026" title="subsonic" src="http://producerism.com/wp-content/uploads/2011/09/subsonic.png" alt="" width="478" height="99" /></a></p>
<p>Subsonic is a great little app (windows, osx, linux) that not only handles your audio library, but will also stream video to your browser, tablet, phone, etc.  It was originally made to stream audio files (mp3, mp4, flac, wav, etc.) but has since evolved to handling just about any audio or media format.  Want to stream a 1080p MKV video to your cellphone/tablet, but your connection is only 3G?  No problem, just set quality to low (e.g. 150kbps) and hit play.  Of course, if you aren't limited by connection speed, the only limit is how much your HTPC/Media Server computer can handle.  Personally, my mini-ITX AMD Zacate that runs on less than 50W can't handle realtime video transcoding, so if that's what you want, an Intel i3 is probably the lowest you can go.  For streaming audio however, a low-power CPU is just fine.  Making media accessible to friends and family is easy with Subsonic too.  You can create accounts for different people, see what media they are playing, and chat with them on the web-based interface. Recent updates to Subsonic have also enabled sharing of songs/albums with direct links, and Last.fm audio scrobbling.</p>
<p><img class="alignnone size-full wp-image-1027" title="subsonic" src="http://producerism.com/wp-content/uploads/2011/09/subsonic.jpg" alt="" width="743" height="328" /></p>
<h2>Serving Other types of Media (eBooks, Comics, PDF, etc.)</h2>
<p>We could stop here, and most people would.  However, this is still an incomplete solution, since digital media also covers written material!  For anyone with a tablet especially, this is a great way to have an all-in-one solution.  One of the undisputed tools for organizing an eBook collection is the <a href="http://calibre-ebook.com/">Calibre eBook Manager</a>.  Not only does it organize and allow you to read/convert/export your library of epub/pdf/txt/mobi files, but it also has a built-in web-based server!</p>
<p><a href="http://www.mobileread.com/forums/showthread.php?t=31555"><img class="alignnone size-full wp-image-1029" title="calibreserver" src="http://producerism.com/wp-content/uploads/2011/09/calibreserver.jpg" alt="" width="743" height="328" /></a><br />
Outstanding, so now there is a way to access your eBook files, along with all sorts of meta information.  Using this in conjunction with a free service like <a href="http://www.magicscroll.net/">MagicScroll</a> will allow you to not just access, but read your books online.  Speaking of reading online, how about a similar web-based service for reading through a comic collection?</p>
<p><a href="http://sourceforge.net/projects/cbrserver/">Comic Book Archive Server (CBR Server)</a> is a great solution for making your comic collection accessible online.  It requires about 15 minutes of setup, since you need to manually download 7-zip, ImageMagick and Java.  There are also a few issues that need to be worked out (out of memory errors, missing features, etc.) as development continues.</p>
<p><a href="http://sourceforge.net/projects/cbrserver/"><img class="alignnone size-full wp-image-1030" title="cbrserver" src="http://producerism.com/wp-content/uploads/2011/09/cbrserver.jpg" alt="" width="599" height="447" /></a></p>
<h2>Accessing and Controlling the HTPC Remotely</h2>
<p>With all of these web-interfaces for accessing media (Subsonic, Calibre, CBR Server, etc.) you may still need more ways to get to other files and folders.  This is where the following utilities can help out tremendously:</p>
<p><a href="http://www.tightvnc.com/"><img class="alignnone size-full wp-image-1031" title="tightvnc" src="http://producerism.com/wp-content/uploads/2011/09/tightvnc.jpg" alt="" width="498" height="107" /></a></p>
<p><a href="http://www.tightvnc.com/">TightVNC</a> is like any other VNC software - it allows you to remotely connect to your HTPC/Media Server from another computer, phone, browser, etc.  This is helpful for all sorts of reasons, so highly recommended.  There are other flavors of VNC out there as well like RealVNC, UltraVNC, etc.  I just prefer TightVNC as I've been using it the longest.</p>
<p><a href="http://db.tt/PjNfYEh"><img class="alignnone size-full wp-image-1032" title="dropbox" src="http://producerism.com/wp-content/uploads/2011/09/dropbox.jpg" alt="" width="350" height="90" /></a></p>
<p><a href="http://db.tt/PjNfYEh">Dropbox</a> is one of my "must-have" tools.  There are only two kinds of people... those that use <a href="http://db.tt/PjNfYEh">Dropbox</a>, and those that haven't heard of it (or don't understand it).  How does it fit into this whole HTPC/Media Server setup?  Imagine for a moment you want an easier way to download .nzb or .torrent files.  Simply point your sabnzbd/torrent client to a folder inside your dropbox called "dropbox/nzbs" (or "dropbox/torrents").  Now anywhere you have Dropbox installed, you can just save a link and know that your HTPC will start downloading right away - no matter where you are.</p>
<h1>The Hardware</h1>
<p>Just about all of this article so far has been hardware agnostic.  No matter what your setup, you should be able to install all of the applications mentioned so far (except for maybe Maximus Arcade, which is only for Windows).  That being said, I mentioned that my personal goal was to have a mini-itx machine that could run on less than 50W, and one that costs less than $400.  Since I originally put my machine together, there are probably a few more options that have opened up.  Anyways, here is my build list ($426 total as of 9/4/2011, at the time I purchased there were a few sales, so it was under $400):</p>
<ul>
<li>$110 - mobo/cpu: <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16813157247">ASRock E350M1/USB3</a></li>
<li>$60 - case: <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16811163174">Silverstone ML03B</a></li>
<li>$27 - ram: <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16820134718">Kingston 4GB (2 x 2GB) low profile</a></li>
<li>$95 - ssd: <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16820167044">Intel 320 40GB</a></li>
<li>$65 - hdd: <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16822148725">Seagate Barracuda Green 1.5TB 5900RPM</a></li>
<li>$46 - psu: <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16817151063">SeaSonic SS-350SFE 350W</a> (was actually too small for the case!)</li>
<li>$20 - fans: <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16811999199">2x ENERMAX UC-8EB 80mm Case Fan</a></li>
</ul>
<p>For the OS, I installed Windows 7 x64, and did not calculate that into the cost.  You may notice I only have 1.5TB of storage, which may seem small for an HTPC/Media Server.  Personally, I delete movies/tv shows after I am done watching them - but if I wanted more space, there is enough room to add another two 3.5in drives, so adding another 4TB of space would be trivial.  I also purchased a compact power supply unit (PSU) thinking that the case needed it, however the Silverstone case was actually made for a regular size PSU.  Not really a big issue for me, since I was stuffing the unit into an entertainment unit.  It runs 24/7 inside of a small space in a wooden entertainment unit, uses around 45W, and the temperature hasn't gotten over 48C.</p>
<h1>Optional Hardware</h1>
<p>Nothing is more annoying, or more certain, than having to buy a few extra odds and ends to complete an HTPC setup.  Your machine may have the perfect combination of hardware and software, but there is always room for improvement.  Here are a few optional additions that can make the difference between a headache and a home theater.</p>
<h2>Slow LAN / Buffering Issues / Streaming over WiFi</h2>
<p>After my setup was complete, I had intermittent issues with buffering.  My network speeds were good, and the WiFi signal was decent, but not always perfect.  Turns out, the actual placement of my wireless router/modem, and the placement of the WiFi antenna on my HTPC had too many obstructions between them (walls, beams, appliances, etc.).  I almost considered running a 50ft ethernet cable across the floor (or in the ceiling) until a friend pointed me towards Powerline Ethernet, which saved the day.  Specifically, the <a href="http://www.amazon.com/NETGEAR-Powerline-200-Adapter-Kit/dp/B0036R9YA6">NETGEAR Powerline AV 200 Adapter Kit</a> ($100).</p>
<p><img class="alignnone size-full wp-image-1038" title="powerline" src="http://producerism.com/wp-content/uploads/2011/09/powerline.jpg" alt="" width="640" height="267" /></p>
<p>The Powerline kit basically lets you use your electrical system as an ethernet cable.  You plug one of the adapters into a power outlet next to your modem/router, and then connect it to the modem/router with an ethernet cable.  Then, anywhere else in the house you plug the other adapter into an outlet, and run an ethernet cable from the adapter into your HTPC.  Instantly, all of the buffering issues were gone.  There aren't many products out there which are truly "plug and play," but this is one of them.  No setup needed whatsoever, it just works... and after troubleshooting network issues for over a week, it was $100 well spent.</p>
<h2>HDTV Losing Connection with HDMI (Black Screen)</h2>
<p>This was an extremely annoying problem.  Sometimes, when I turned the TV off, or the HTPC went to sleep - the connection between the HDMI on my computer and the TV would get lost.  I would have to manually turn off the HTPC, sometimes I even needed to unplug the power and the HDMI cable before I could get the TV to communicate again.  Turns out this is actually a fairly common problem with HTPCs and certain types of TVs.  What's happening is that the TV has an EDID (Electronic Device ID) which the computer uses to identify where to send the signal.  There is some kind of a "handshake" going on during this process - and if at any time the communication between HTPC and TV is broken, it can be a hassle to get the signal back.  This is where the<a href="http://www.amazon.com/Gefen-EXT-HDMI-EDIDP-HDmi-Detective-Plus/dp/B001RIMZUW"> Gefen HDMI Detective Plus</a> shows it's worth.  It's painful to drop another $85 on a "budget" HTPC, especially when it's close to 1/4 the cost of the whole machine.  Then again, it's hard to put a price on peace of mind.  After reading the Amazon reviews for this unit, it wasn't a very hard sell.<br />
<a href="http://www.amazon.com/Gefen-EXT-HDMI-EDIDP-HDmi-Detective-Plus/dp/B001RIMZUW"><img class="alignnone size-full wp-image-1039" title="gefen" src="http://producerism.com/wp-content/uploads/2011/09/gefen.jpg" alt="" width="640" height="267" /></a></p>
<h2>Mouse, Keyboard, Remote</h2>
<p>There are lots of options for HTPC remotes out there.  Some people swear by Logitech Harmony remotes - some like Boxee remote, etc.  I already had a <a href="http://www.amazon.com/Microsoft-Control-Receiver-Windows-A9O-00007/dp/B00066FIO6">Windows Media Center USB remote</a> and love it.  The backlit rubber buttons are great, and the USB receiver seems to work from anywhere in the room (which is more than I can say for a handful of other remotes I've tried).  I believe it works on RF, so it doesn't need a line-of-sight like InfraRed.  On Amazon the remote is pretty expensive, but I'm guessing that's because it's been discontinued in favor of a newer model.</p>
<p><img class="alignnone size-full wp-image-1040" title="mceremote" src="http://producerism.com/wp-content/uploads/2011/09/mceremote.jpg" alt="" width="398" height="267" /></p>
<p>As for keyboard/mouse, I almost went for a Logitech diNovo, but was scared away by the price and bad reviews.  Instead, I opted for a Logitech unifying <a href="http://www.logitech.com/en-us/mice-pointers/mice/devices/7759">Couch Mouse</a> and a cheap unifying wireless keyboard.  They don't get used much, unless I'm using the HTPC as an actual computer (or for internet browsing / emailing / etc.).  When I do need to use them though, they are invaluable - since typing something out with a remote can take about 50x longer than if you have a regular keyboard close by.</p>
<h2>So what's the real cost?</h2>
<p>If you have been keeping track, this budget, sub-$400 HTPC has slowly gotten more and more expensive with each of these additions.  With the Powerline Ethernet adapter, HDMI detective, and remote/keyboard/mouse, the final cost will probably be closer to $600.  When I first set out to make an HTPC, I kept reading over and over to take my intended budget and double it.  Turns out, that was correct almost to the dollar (my original budget was about $350).</p>
<h1>But Wait, That's Not All!</h1>
<p>There are also lots of browser extensions and user-scripts made for Sabnzbd, CouchPotato, uTorrent, JDownloader, etc.  I may add some updates to this article in the future to cover those as well.  For now, this should be more than enough to inspire you to "cut the cord!"</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/building-the-perfect-htpc-media-server/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Where Corona SDK Falls (kinda) Flat</title>
		<link>http://producerism.com/blog/where-corona-sdk-falls-flat/</link>
		<comments>http://producerism.com/blog/where-corona-sdk-falls-flat/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 15:22:54 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=974</guid>
		<description><![CDATA[Update 10/08/2011:  Instead of making another post to highlight other issues with Corona, I'll just continue to update this article. The Corona SDK is starting to become more and more popular among developers.  In fact, my tutorial on setting up Corona for Windows development is still the most popular post on this site.  Since I've posted, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update 10/08/2011:</strong> <strong> </strong>Instead of making another post to highlight other issues with Corona, I'll just continue to update this article.</p>
<p>The Corona SDK is starting to become more and more popular among developers.  In fact, my<a href="http://producerism.com/blog/how-to-develop-in-corona-sdk-on-windows/"> tutorial on setting up Corona for Windows development</a> is still the most popular post on this site.  Since I've posted, lots of other great game developers have been posting about Corona, along with Jesse Warden, who seems to have been making all sorts of contributions.  In fact <a href="http://jessewarden.com/2011/08/intro-to-corona-1-hour-45-minutes-hd-video.html">here is a video from Jesse Warden that is almost 2 hours long, covering the process for developing in Corona</a> (on a Mac).  Needless to say, there is lots of momentum and excitement surrounding Corona, and I'd say with good reason.  Corona is a great solution for creating games quickly, which will work on (most) Android devices and iOS.  Even with all of the Ant or Maven scripts in the world, it doesn't seem like there has been an easier solution made for cross-platform development yet.</p>
<p><img class="alignnone size-full wp-image-993" title="Corona" src="http://producerism.com/wp-content/uploads/2011/09/dirty_corona.jpg" alt="" width="584" height="275" /></p>
<p>(<a href="http://www.flickr.com/photos/usachicago/3153873091">image credit</a>: John W. Iwanski aka Chicago Man)<span id="more-974"></span></p>
<p>With all of this in mind, there are still a few things about Corona (aka Ansca Mobile) that seem to be counter-intuitive/counterproductive.   This criticism isn't meant to be stated matter-of-factly, so if any of these gripes are unwarranted, please let me know in the comments.  <a href="http://joshblog.net/2011/05/16/adventures-with-corona-part-2-where-corona-needs-improvement/">Here is another good blog post</a> from a Flash/Corona developer which covers some of the same issues brought up in my article.</p>
<h2>Android Support</h2>
<p>The marketing copy on Corona's website states (emphasis mine) "Corona is the only<strong> complete solution</strong> for developing across platforms,<strong> OS versions</strong>, and screen sizes," but that's not <em>entirely</em> true.  Since Corona SDK's<a href="http://developer.anscamobile.com/content/coronasdk-release-notes-591"> release #591</a>,<strong> only Android OS 2.2+ and ARMV7 devices are supported</strong>.  This means there is a long list of fairly recent Android devices which cannot run apps made with Corona (the best list I could find of ARMV6 devices was <a href="https://wiki.mozilla.org/Mobile/Platforms/Android#System_Requirements">here</a>.  It includes HTC Aria, Hero, Legend, LG Optimus, Motorola Backflip, Samsung Galaxy, ViewSonic ViewpPad, ZTE Blade/San Francisco and others). <del> Not a deal-breaker, but it is worth mentioning, since Ansca Mobile doesn't make this very obvious on the website.</del>  It also seems as though there will be no intention of adding support in the future.</p>
<p>Also, there are a few (somewhat important) features in Corona which only work for iOS.  <del>For example, in the notes on <a href="http://developer.anscamobile.com/reference/index/mediashow">media.show()</a>, it mentions anything related to the device Camera or Photo/Media library is for iOS only.</del>  Same goes for all of the <a href="http://developer.anscamobile.com/reference/maps">map</a> features - iOS only.  While this probably isn't a reason to look elsewhere, it might be.  Again, it's not overly obvious that Android isn't supported.</p>
<p><strong>Response from Ansca Mobile:</strong></p>
<blockquote><p>As far as Android goes, everyone knows it's incredibly fragmented. There's tons of different devices, tons of form factors, versions, etc. Basically, in order to continue to move the product forward (in terms of Corona + Android), we had to draw the line somewhere. Android 2.2 and Armv7 just so happens to be where that line was drawn. For developers who absolutely need support for an old version of Android and anything below the Armv7 architecture, then Corona's definitely not for those developers.</p></blockquote>
<h2>Android Performance</h2>
<p>All devices are not created equal.  Although the hardware specs for Android devices vary greatly (compared to iOS devices) the general consensus among the Corona development community is that on average, Android performance is worse than iOS performance when using Corona.  This is even highlighted by popular third-party library developers of Particle Candy and the Lime library.  The <a href="http://x-pressive.com/ParticleCandy_Corona/download.html">particle candy download page</a> explicitly states:</p>
<blockquote><p>please keep in mind that Corona may run slower on Android devices than on iOS devices. Also, not all of the SDK's features are available on Android devices yet. Ansca is working hard, however, to further improve both, performance and feature richness on Android devices.</p></blockquote>
<p>The developer for Lime made a <a href="http://developer.anscamobile.com/forum/2011/07/26/update-performance#comment-58843">similar observation on the Corona SDK forums</a>:</p>
<blockquote><p>The main performance issues I find, which are certainly a lot more prominent on Android, are down to how many tiles ( or other Display Objects/Groups ) are active.</p></blockquote>
<p><a href="http://developer.anscamobile.com/forum/2011/07/07/dissapointing-android-performance">Here is a thread on the forums</a> where you can see for yourself how this can be a headache to developers, and one without any obvious solutions other than waiting for Corona to improve Android performance.</p>
<h2>Can't Trust Simulator Performance</h2>
<p><img class="alignnone size-full wp-image-989" title="performance_issues" src="http://producerism.com/wp-content/uploads/2011/09/performance_issues.jpg" alt="" width="743" height="225" /></p>
<p>This might seem obvious, since your development workstation is almost certainly more powerful (by a few orders of magnitude) than your mobile device.  You would expect a 64bit machine with 8gigs of RAM to outperform your phone, but it might not be obvious where the exact threshold is.  For example, just by browsing the forums there are many developers having issues with performance discrepancies between the simulator and devices (<a href="https://developer.anscamobile.com/forum/2011/05/09/towerdefense-takes-all-cpu-iphone">here is just one example</a>).  Undoubtedly, there will always be developers having issues with something or another, and that doesn't mean it's the software's fault.  However, just about everyone that has done game development has run into performance issues at one time or another, and the typical remedy is debugging and profiling.  Both of which have very limited support right now (at least for windows).</p>
<p>This is further highlighted by a third-party Corona SDK library called <a href="http://www.justaddli.me/">Lime</a>, which offers lots of helper classes and <a href="http://www.justaddli.me/features.php">features</a>.  Unfortunately, with some implementations there are hardware-related performance issues.  What's tricky is that it's not always obvious what the exact problem is - since some games work without issues.  When that's the case, everything is fine... but if you are having issues, you may find yourself tweaking code endlessly without any clear resolution.  Code that seems like it should work just fine (and appears to do so in the simulator) might not work on your device.</p>
<p>Again, this could all be code or game design related, but the fact that there are many developers having similar issues (and not a whole lot of answers) makes this noteworthy.</p>
<p><strong>Response from Ansca Mobile:</strong></p>
<blockquote><p>... the other issues you have (such as inconsistent simulator/device performance, etc), all we ask is that if you find something, to please create a test case (a small example project that sort of reproduces and isolates the bug), and then submit a bug report. The bug base is engineering's "to-do list" so to speak, so that's definitely the fastest way to get something resolved. The bug reporter is here:</p>
<p><a href="http://developer.anscamobile.com/content/bug-submission">http://developer.anscamobile.com/content/bug-submission</a></p>
<p>(When you log into your account on anscamobile.com, you can click the 'Report a Bug' link at the top to get back to that page at any time)</p></blockquote>
<h2><del>Developer Support</del></h2>
<p>Since this article was originally posted, the Corona forums have been updated to allow non-verified users read-only access to forums - also, by signing up and verifying an account (no subscription needed, trial users are ok) you have full access to read and post in the support forums.  This was perhaps main topics of this post, and the issue was completely resolved within a few days.  I believe that speaks volumes about the developer support Ansca Mobile provides for it's Corona SDK users, which is vital to a thriving new language / API / developer tool.</p>
<h2>Debugger</h2>
<p>The debugger for Corona SDK leaves a lot to be desired.  It's basically a command-line debugger, so any debugging you do is done via typing actions  into a terminal/command prompt.  This is obviously a bit of a hassle when trying to debug, although better than nothing! (For a while, there was no debugging option for Windows).  There are often times you will just get a "run time error at Line ##," which is certainly helpful to track down where it's happening, but there's no other information given (e.g., what type of error was it?)</p>
<h2>Lua Library Support</h2>
<p>Corona SDK uses Lua for the scripting, then parses this into the proper formats on their servers during the build process.  This was a great idea, since Lua can be very powerful and flexible.  However, as <a href="http://praxisstalled.blogspot.com/2011/09/few-thoughts-on-cross-platform.html">another blogger pointed out</a>:</p>
<blockquote><p>Lua has a rich library of code available to it, but Corona will not work with any of the many binary libs. In our case, this lead to us having to abandon interfacing with a web service using AES encryption. In general, you are restricted to whichever advance features the development team have included and exposed. This includes OpenFeint, Flurry, and an older version of the Facebook Connect library. For Twitter or Facebook using OAuth you'll have to roll your own solution (unless I decide to share mine…).</p></blockquote>
<h2>Authorization Process</h2>
<p>It's not unusual for software to limit the number of installations you can have across multiple machines.  <a href="Worse yet, let's say you installed onto a VirtualBox instance, or onto a computer which you don't have access to anymore, or one that has been reformatted.  ">Corona SDK limits you to 2 installs per license</a>.  That means if you have a desktop and a laptop, all your installs are accounted for.  However, what if your desktop and laptop are both PC? You also need a computer running OSX to build for iOS devices, which would put you over the 2 machine limit.  Same for running a virtual OS, with a program like VirtualBox.  If you have Corona installed on your desktop, and within a VirtualBox instance, both of your licenses are used up, and you will not be able to install on any other machines or VirtualBox instances.</p>
<p>The only way to "deauthorize" a computer, is by selecting an option in the Corona Simulator on that computer.  Let's say you installed onto a VirtualBox instance which has since been deleted, or onto a computer which you don't have access to anymore, or one that has been reformatted.  Unfortunately, you are out of luck and the only solution is to fill out a support ticket - so that Ansca staff can manually remove authorizations.  As far as I know, there is no other way to deauthorize your machine.  As you can imagine, this has the potential to turn into a very <a href="http://developer.anscamobile.com/forum/2011/09/06/device-authorization-reset">long and frustrating process</a> (link goes to Corona forums, in a thread where someone has this exact problem).</p>
<p>Long story short, you may want to plan out your development process and think carefully about how many machines or Virtual Machines you will need for development.</p>
<h2>Limited Subdirectory Support</h2>
<p>When working on any apps, not just games, the organization of your code and assets can be a huge factor in how efficient your development process is.  Unfortunately for Android developers, Corona does not currently support subdirectories for all of your assets, at least not in a very robust way.  That means most of your non-lua files (music, art, etc.) are all in a single folder.  This may not be a huge issue if the number of files in your project is small (less than 20), however it can become a nightmare for more complex projects.  <a href="http://www.twitvid.com/NMZYV">Here is just a small example of how this limitation could get out of control.</a></p>
<p><strong>note: </strong>This limitation was not obvious to me right away... the Corona Simulator seemed to allow subdirectories without any problems.  Issues only arise when you build the file and try to actually run on your device.</p>
<p><strong>update:</strong>  <a href="http://blog.anscamobile.com/2011/10/daily-build-feature-lua-files-in-folders/">Since build #619, subdirectory support is available for iOS apps, but still not Android</a>.</p>
<h2>Other Gripes</h2>
<p>Honestly, there aren't too many other gripes I have about Corona.  It seems like the perfect solution when everything works according to plan, and when you only need to use the features that are supported.  If you venture into uncharted territory however, any troubleshooting or debugging could be entirely up to you.  The community is extremely helpful, as are the admins, but there does seem to be a slight element of luck/magic/voodoo surrounding performance.  Or maybe it's just a result of incomplete/insufficient documentation - either way, this small list of gripes encompasses the main issues I have noticed with Corona.  Feel free to add on if you have others, or if you have alternate solutions.</p>
<p><strong>Follow up thoughts:</strong></p>
<p><strong></strong>Another important thing to note is Ansca Mobile's quick response to community feedback.  It seems that whenever a blog/forum/etc. post is published anywhere online, Ansca Mobile staff are there to read it and provide responses within hours.  I mentioned to the staff in an email that  I haven't discovered a development community this enthusiastic since Actionscript 3 came out.  Most of the other write-ups about Corona SDK state similar things - and now that I have access, I'll be speaking with the rest of you Corona developers in the forums!  Special thanks to Hetal and Jonathan at Ansca Mobile for the feedback.  If anyone notices other mistakes/misunderstandings in this post, please let me know via email / comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/where-corona-sdk-falls-flat/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Project: SumFans (jQuery, crossrider, &amp; gdata)</title>
		<link>http://producerism.com/blog/project-sumfans-jquery-crossrider-gdata/</link>
		<comments>http://producerism.com/blog/project-sumfans-jquery-crossrider-gdata/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 02:48:22 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=925</guid>
		<description><![CDATA[My latest project requires a brief explanation, as it solved a very particular problem.  As a musician, it's pretty common to see my work posted (pirated) all over youtube, myspace, last.fm, etc.  To be honest, I'm happy my music is getting exposure, either through iTunes or ThePirateBay - makes no difference to me.  With that [...]]]></description>
			<content:encoded><![CDATA[<p>My latest project requires a brief explanation, as it solved a very particular problem.  As a musician, it's pretty common to see my work posted (pirated) all over youtube, myspace, last.fm, etc.  To be honest, I'm happy my music is getting exposure, either through iTunes or ThePirateBay - makes no difference to me.  With that said, the problem I found is that it's difficult to get an idea on how much exposure all of the music is getting, whether I uploaded it, or if it was uploaded by someone I never met.  My solution to that problem is something called <a href="http://producerism.com/sandbox/sumfans/">SumFans</a>.</p>
<p><a title="SumFans" href="http://producerism.com/sandbox/sumfans/">Click here for a demo of SumFans</a></p>
<p><a href="http://producerism.com/sandbox/sumfans/"><img class="alignnone size-full wp-image-932" title="sumfans-screenshot" src="http://producerism.com/wp-content/uploads/2011/06/sumfans-screenshot.png" alt="" width="589" height="350" /></a></p>
<p>When you post a video to your own youtube account, there are plenty of stats to look at.  However, if your media was posted on someone else's account, it's much harder to get the same stats.   That's where this project started - as a way to easily calculate all of the views my music has gotten, regardless of what account it was posted under (or even what site it was posted to!).  After a few long nights of coding and reading through lots of APIs, I came up with SumFans (I liked "FanSum" better, but it was taken).</p>
<p>The final result uses a few different components:</p>
<ul>
<li>PHP - handles communcation with database</li>
<li>mySQL - database that stores all media information, and a log of views</li>
<li>JS - lots of different jQuery libraries (<a href="http://jqueryui.com/">UI</a>, <a href="http://code.google.com/p/flot/">flot</a>, <a href="http://tinysort.sjeiti.com/">tinysort</a>, <a href="http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/">prettyPhoto</a>, <a href="http://www.hintzmann.dk/testcenter/js/jquery/textshadow/">textshadow</a>)</li>
<li><a href="http://crossrider.com/">crossrider</a> - an awesome service that allows you to create cross-browser compatible extensions.</li>
<li>APIs - mostly REST calls for <a href="http://www.last.fm/api">last.fm</a> and YouTube (via <a href="http://code.google.com/apis/youtube/2.0/developers_guide_json.html">gdata</a>)</li>
</ul>
<p><span id="more-925"></span></p>
<p><span style="font-size: 20px; font-weight: bold;">Creating Cross-Browser Extensions with Crossrider!</span></p>
<p><a href="http://crossrider.com/"><img class="alignnone size-full wp-image-936" title="crossrider-logo" src="http://producerism.com/wp-content/uploads/2011/06/crossrider-logo.png" alt="" width="388" height="99" /></a></p>
<p>If you are familiar with <a href="http://www.greasespot.net/">greasemonkey</a> or <a href="http://www.chromium.org/developers/design-documents/user-scripts">userscripts</a>, then using crossrider should be pretty simple.  If you haven't heard of any of these, just think of crossrider as javascript code that runs each time you load a page.  The problem with greasemonkey scripts are that they only work (as expected) in Firefox.  The problem with userscripts in chrome, is that you can't make cross-site scripting requests (XSS).  Crossrider solves both of these problems, and better yet, it actually comes with jQuery support built in.  <del>Crossrider is currently in beta, but if you <a href="http://twitter.com/#!/crossrider">follow their twitter feed</a>, you can snag an invite code like I did.</del> <strong>UPDATE:</strong> The folks at Crossrider have offered to give readers of this blog free invites! <a href="http://crossrider.com/beta?code=SUMFANS">http://crossrider.com/beta?code=SUMFANS</a> (thanks Shmueli!)</p>
<p>So what does crossrider have to do with any of this?  Well, we have a database that has all of the media information to track, but depending on the website that the media is hosted on (youtube, myspace, last.fm, etc.) there are different types of info that needs to be captured.  Even once we identify that information, how can we enter it into the database <strong><em>easily</em></strong>?  Take a look at the database tables being used for a better idea (youtube, myspace, and last.fm, respectively):</p>
<p><img class="size-full wp-image-946   alignnone" style="margin-right: 20px;" title="sumfans-db-youtube" src="http://producerism.com/wp-content/uploads/2011/06/sumfans-db-youtube1.png" alt="" width="119" height="266" /><img class="size-full wp-image-945   alignnone" style="margin-right: 20px;" title="sumfans-db-myspace" src="http://producerism.com/wp-content/uploads/2011/06/sumfans-db-myspace1.png" alt="" width="208" height="266" /><img class="size-full wp-image-944" title="sumfans-db-lastfm" src="http://producerism.com/wp-content/uploads/2011/06/sumfans-db-lastfm1.png" alt="" width="288" height="266" /></p>
<p>As you can see, all we need for YouTube are the video IDs.  For myspace and last.fm, we need the artist and track names.  Now that we know what information needs to be stored, the hard part is actually finding all of this data and manually entering it into the database.  This is where crossrider comes to save the day!  Using crossrider, I wrote a script that will detect (using regexp) if you are looking at a Youtube video, or if you are on a last.fm track page).  If so, a small button will display on the bottom right of the browser window, which allows you to add or remove the media item to/from the database.  I got the idea from a <a href="http://userscripts.org/scripts/review/88470">userscript</a> written for <a href="http://couchpotatoapp.com/">CouchPotato</a> (more on CouchPotato in a future post!).  Anyways, take a look at these screenshots:</p>
<p><img class="alignnone size-full wp-image-951" style="margin-right: 20px;" title="sumfans-youtube-button" src="http://producerism.com/wp-content/uploads/2011/06/sumfans-youtube-button.png" alt="" width="383" height="360" /><img class="alignnone size-full wp-image-950" title="sumfans-lastfm-button" src="http://producerism.com/wp-content/uploads/2011/06/sumfans-lastfm-button.png" alt="" width="383" height="360" /></p>
<p>The screenshots are pretty small, but if you look closely in the bottom right corner, there is a button which reads "Remove (video id) from list."  By the time you see that button show up, the crossrider extension has already connected to my site, and checked whether or not the video on that page is in the database.  When you click on the button, crossrider sends an ajax command back to my site, which in turn adds (or removes) an entry for that media item into one of the database tables you saw above.  Once I spend more time with regexp, I will add support for myspace as well.  For now, I've just been adding myspace entries manually into the database.</p>
<h2>Getting the View Data</h2>
<p>Great, so there's a database storing our media information, and a browser extension which makes the process much easier for YouTube and last.fm items (with myspace and others on the way).  How do we actually use this data to get the number of views for each item?  Again, the process is a little different for each website.</p>
<h3>YouTube</h3>
<p>Getting stats from YouTube is actually pretty easy.  I've attempted a similar project to SumFans in the past, but this was before the sweet JSON YouTube GData API was out.  Originally I was using the <a href="http://framework.zend.com/manual/en/zend.gdata.html">Zend Gdata PHP library</a>, which was pretty cumbersome and not as easy to install on a shared host.  With the JSON API, it couldn't be much easier.</p>
<p>For example, this call:</p>
<pre class="brush:javascript">http://gdata.youtube.com/feeds/api/videos/BPOqptEDLIo?v=2&amp;alt=jsonc</pre>
<p>Returns something like this (I've omitted some of the data that gets returned, for space):</p>
<pre class="brush:javascript">{
   "apiVersion":"2.0",
   "data":{
      "id":"BPOqptEDLIo",
      "uploaded":"2009-08-25T10:24:42.000Z",
      "updated":"2011-05-22T04:07:57.000Z",
      "uploader":"DaFlowContinuum",
      "category":"Music",
      "title":"sound scientists - it's ova (instrumental)",
      "description":"ALBUM: sound scientists instrumentally sound (2009) This instrumental-only album was produced by Trioptic of the Sound Scientists, and features 20 beats created over the last 5 years.",
      "duration":260,
      "rating":5.0,
      "likeCount":"8",
      "ratingCount":8,
      "viewCount":11629,
      "favoriteCount":95,
      "commentCount":33
   }
}</pre>
<p>Pretty much all of the information you could ever want from a YouTube video, right?  The bad news is that getting the views from other websites isn't as easy.</p>
<h3>last.fm</h3>
<p>The API for last.fm is pretty easy to use as well, with the <a href="http://www.last.fm/api/show?service=356">track.getinfo</a> call.  For some reason however, I couldn't always rely on a response when called from the client side (jQuery).  Instead, I made the same call, but on the server with PHP.  Then I used file_get_contents to return the JSON.  Not the ideal solution, but it was the only thing that I found to work consistently.  Here is a quick snippet:</p>
<pre class="brush:php">$url = "http://ws.audioscrobbler.com/2.0/?method=track.getinfo&amp;artist=$artistName&amp;track=$trackName&amp;format=json&amp;api_key=$apiKeyLastFM";
        $str = file_get_contents($url);
        echo $str;</pre>
<p>Pretty much like the gdata API, we get this response (again, some of the data has been omitted):</p>
<pre class="brush:javascript">{
   "track":{
      "name":"Cinco",
      "url":"http:\/\/www.last.fm\/music\/Sound+Scientists\/_\/Cinco",
      "duration":"191000",
      "listeners":"226",
      "playcount":"770",
      "artist":{
         "name":"Sound Scientists",
         "mbid":"",
         "url":"http:\/\/www.last.fm\/music\/Sound+Scientists"
      },
      "album":{
         "artist":"Sound Scientists",
         "title":"Instrumentally Sound",
         "url":"http:\/\/www.last.fm\/music\/Sound+Scientists\/Instrumentally+Sound"
      }
   }
}</pre>
<h3>Myspace, iSound and other sites</h3>
<p>As you can see, YouTube and last.fm already have an API which provides the number of views/playcounts for us.  Myspace also has an <a href="http://wiki.developer.myspace.com/index.php?title=Media_Items_APIs#Examples">API for getting information about media items</a>, but unfortunately, they don't consider music or videos as media - only pictures.  And it <a href="http://developer.myspace.com/Community/forums/p/10808/52915.aspx#52915">doesn't look like they intend to add support</a> for music/video views either.  My solution for this, was to simply use jQuery selectors to parse through the contents of a myspace page, and look for the views.  Here is the exact code:</p>
<pre class="brush:javascript">var plays = parseInt(
    $('.songInfo span:contains("Plays:")', data)
        .next()
        .html()
        .replace("," , "")
);</pre>
<p>Pretty short and sweet, it just grabs the number of plays, removes the commas, and returns an Int.  The code for <a href="http://www.isound.com/sound_scientists">iSound </a>is similar:</p>
<pre class="brush:javascript">var plays = parseInt(
    $('.white-holder-list.stats span.plays', data)
        .html()
        .replace("," , "")
);</pre>
<p>How am I actually loading the contents of these remote pages into jQuery?  Well, I just make a $.ajax call to something like <strong>ajax.php?action=getHTML&amp;url=http://somesite.com</strong>.  Inside ajax.php I have this:</p>
<pre class="brush:javascript">	case 'getHTML':
		die(file_get_contents($_GET['url']));
	break;</pre>
<p>So when I make the call, the response is just the HTML of the rendered page as if it had rendered in my own browser.  This is far from the best solution, but it's very workable for now, and <del>dealing with jQuery selectors is a trimillion times easier than using PHP to parse the DOM.</del> <em><strong>UPDATE:</strong> I've recently discovered <a href="http://code.google.com/p/phpquery/">phpquery</a>, which is actually based on jQuery! I'll have to cover that some other time.  In lieu of this discovery, the next update is most likely going to parse the DOM in PHP on the server, and only return the data needed (plays).</em></p>
<h2>Displaying the View Data</h2>
<p>After going through all of this hard work to get all of these numbers, it's time to display them in a cool way.  The current design is pretty overkill, since I'm testing out a few different ways of visualizing this information.  Here is the screenshot (and link) from above for a quick reference:</p>
<p><a href="http://producerism.com/sandbox/sumfans/"><img title="sumfans-screenshot" src="http://producerism.com/wp-content/uploads/2011/06/sumfans-screenshot.png" alt="" width="589" height="350" /></a></p>
<p>There are a few different types of information being collected.  Since the <a href="http://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html#Understanding_JSONC">YouTube GData API returns so much useful data</a>, it would be a shame not to make use of it.  The Total Ratings, Comments, and Favorites are only collected from YouTube.  As for the other sites, SumFans only cares about total number of views/plays/etc.  As jQuery gets responses back with the number of views for each media item, a small div is created with a thumbnail, and number of views.  The progress bar is just using the base <a href="http://jqueryui.com/demos/progressbar/">jQuery UI</a>.  For YouTube results, clicking on the number of views for each video will launch that video via <a href="http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/">prettyPhoto</a>.  Then, once all of the views have been calculated, I use <a href="http://tinysort.sjeiti.com/">tinysort.js</a> to organize the divs from most number of views to least.  Finally, to create the graph I use <a href="http://code.google.com/p/flot/">flot</a>, which is another really awesome jQuery plugin which makes creating interactive graphs extremely easy.  For example, here is the actual database table for the log:</p>
<p><img class="alignnone size-full wp-image-959" title="sumfans-db-log" src="http://producerism.com/wp-content/uploads/2011/06/sumfans-db-log.png" alt="" width="280" height="209" /></p>
<p>Here is the PHP and mySQL to grab that information and return it in JSON:</p>
<pre class="brush:php">    case 'getViews':

        $query = "
            SELECT
                views, date, sources
            FROM
                log
            ORDER BY
                date
            ASC
        ";

        $result = mysql_query($query);
        if(!$result) die();

        $videos = array();

        while($row=mysql_fetch_assoc($result))
        {
            $videos[] = array($row['date'], $row['views'], $row['sources']);
        }

        echo json_encode($videos);
        return false;

    break;</pre>
<p>And finally, the javascript code for creating a graph with that JSON using flot is this:</p>
<pre class="brush:javascript">        $.getJSON('ajax.php?action=getViews', function(data){

            var lineViews = [];
            var lineSources = [];

            $.each(data, function(index, value){
                lineViews.push([mysqlTimeStampToDate(value[0]).getTime(),value[1]]);
                lineSources.push([mysqlTimeStampToDate(value[0]).getTime(),parseInt(value[2])*3000]);
            });

            var data = [{ data: lineViews, label: "Views" }];
            var plot = $.plot($('#graph').slideDown(), data);</pre>
<p>Another feature I'm currently working on is adding interactivity to each of the nodes on the graph.  Here is what it currently looks like when you roll over any of the nodes inside of the generated flot:</p>
<p><img class="alignnone size-full wp-image-960" title="sumfans-flot" src="http://producerism.com/wp-content/uploads/2011/06/sumfans-flot.png" alt="" width="368" height="178" /></p>
<h2>Next Steps</h2>
<p>The ultimate goal for SumFans is to be open source, so that anyone else can use this same solution for tracking media exposure across various sites.  I have lots of high-level ideas floating around, like a repository where anyone can post a regexp script for a website, and then SumFans (both the site, and the crossrider extension) will automatically display a button on that website when it detects media.  Or even a wordpress plugin, to make this even easier for non-developers.  Speaking of non-developers, perhaps a hosted service that doesn't require a developer at all, just a login.  The latter might venture into some legal gray area, so that's much farther down the road.</p>
<p>There are also some small issues I'm trying to resolve, other than the ones mentioned already.  For example, as soon as you install the SumFans crossrider extension, the first time you visit a last.fm or Myspace page with media on it, you will be prompted for the location of the ajax.php files to send/receive data to/from.  I'm not aware of a crossrider "options" panel, so I'm just using a standard javascript prompt command.  And apparently, IE hates that, and won't display it.  I also tried making an input form with jQuery UI, <a href="http://trentrichardson.com/Impromptu/">Impromptu</a>, and <a href="http://thrivingkings.com/apprise/">Apprise</a>.  Unfortunately the problem (in IE, of course) is that the div shows up behind the flash content on a youtube page.  The workaround will probably be to display the input as a small form on the bottom of the window, next to the "Add/Remove (video) to/from list" button.</p>
<p>Finally, and most importantly, I plan on adding LOTS more sites and trackers for views (e.g. Grooveshark, facebook, torrent/download sites, etc.)</p>
<h2>Conclusion</h2>
<p>That's pretty much how far I've gotten with SumFans.  There's quite a bit more code making everything work.  The most interesting component of all this, is probably Crossrider.  I'll be posting the script I made for that very soon, along with the PHP, mySQL, and all other code as soon as I add a little more polish.  Hope someone finds all of this of interest!  Otherwise, I'm still perfectly happy with just using it as a personal tool to keep track of who's listening to my music!</p>
<p>p.s. I wanted to add that <a href="http://jsonformatter.curiousconcept.com/">this json formatter tool</a> was beyond helpful during the entire process, and I don't imagine I could have lived without it!</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/project-sumfans-jquery-crossrider-gdata/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to disable automatic pausing in Flixel 2.5</title>
		<link>http://producerism.com/blog/how-to-disable-automatic-pausing-in-flixel-2-5/</link>
		<comments>http://producerism.com/blog/how-to-disable-automatic-pausing-in-flixel-2-5/#comments</comments>
		<pubDate>Sun, 08 May 2011 23:53:44 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=892</guid>
		<description><![CDATA[Since Flixel 2.5 was just released, I've been having fun playing around with a few things, like the new camera system, pathfinding and a few other features. I've also been trying to integrate some networked multiplayer gameplay, and one of the first things I needed to do was remove the built-in automatic pausing whenever the [...]]]></description>
			<content:encoded><![CDATA[<p>Since <a href="http://flixel.org/features.html">Flixel 2.5</a> was just released, I've been having fun playing around with a few things, like the new <a href="http://flixel.org/features.html#cameras">camera system</a>, <a href="http://flixel.org/features.html#pathfinding">pathfinding</a> and a few other features.  I've also been trying to integrate some networked multiplayer gameplay, and one of the first things I needed to do was remove the built-in automatic pausing whenever the stage loses focus.  After searching google (and the code) for some solutions, almost all of them required changing the flixel code.  Instead, here is a pretty simple solution you can add to your main class (which should be extending FlxGame)</p>
<pre class="brush:as3;highlight:[15,16,17,18,19,20]">package
{
	import flash.events.Event;
	import org.flixel.FlxGame;

	[SWF(width="640", height="480", backgroundColor="#000000")]
	public class MyFlxGame extends FlxGame
	{

		public function MyFlxGame()
		{
			super(320, 240, PlayState, 2);
		}

		override protected function create(FlashEvent:Event):void
		{
			super.create(FlashEvent);
			stage.removeEventListener(Event.DEACTIVATE, onFocusLost);
			stage.removeEventListener(Event.ACTIVATE, onFocus);
		}

	}

}</pre>
<p>As you can see, this simply removes the event listeners from ever getting the message that focus was lost.  Hopefully this may help someone else out there looking to do the same thing.  It seems odd there isn't some kind of FlxG.autoPause variable to turn this on/off a little easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/how-to-disable-automatic-pausing-in-flixel-2-5/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>FlashPunk, DAME and Lua Tutorial (Part 6)</title>
		<link>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-6/</link>
		<comments>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-6/#comments</comments>
		<pubDate>Wed, 04 May 2011 23:11:25 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=862</guid>
		<description><![CDATA[In the last part, we covered most of the code in the tutorial, with exceptions to the TilemapGeneratorEntity and FlyingEntity classes.  Let's jump right in. TilemapGeneratorEntity To try and explain it simply, the TilemapGeneratorEntity basically parses an XML file for tilemap information, along with any sprites (like enemies or powerups) we've created within DAME.  It [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-5/">last part</a>, we covered most of the code in the tutorial, with exceptions to the <strong>TilemapGeneratorEntity</strong> and <strong>FlyingEntity</strong> classes.  Let's jump right in.</p>
<h2>TilemapGeneratorEntity</h2>
<p><img class="alignnone size-full wp-image-868" title="level3c" src="http://producerism.com/wp-content/uploads/2011/05/level3c.png" alt="" width="224" height="195" /></p>
<p>To try and explain it simply, the <strong>TilemapGeneratorEntity</strong> basically parses an XML file for tilemap information, along with any sprites (like enemies or powerups) we've created within <strong>DAME</strong>.  It then creates a graphic to represent the tilemap, a graphic to represent the hit area to collide with, and optionally creates sprites (like enemies) and adds them to the game.  Take a look at how a new <strong>TilemapGeneratorEntity </strong>is instantiated on <strong>line 73</strong> of <strong>TestWorld.as:</strong></p>
<pre class="brush:as3;first-line:73">var testMap:TilemapGeneratorEntity = new TilemapGeneratorEntity(Assets.LEVEL_TEMPLATES_XML, Assets.BG_TILES, mapLayer, "level", _totalMapsWidth, 0, true, false);</pre>
<p><span id="more-862"></span>As you can see, we are passing in a few different parameters to our <strong>TilemapGeneratorEntity</strong>:</p>
<ul>
<li><strong>Assets.LEVEL_TEMPLATES_XML</strong> - this is the XML file that we exported from DAME.</li>
<li><strong>Assets.BG_TILES</strong> - this is the tilemap image that we used when creating the map.</li>
<li><strong>mapLayer </strong>- this is a string that represents the XML node of the tilemap/sprites (e.g. "template3")</li>
<li><strong>"level"</strong> - this is the collision type, which is basically an ID for this collision group (called "level").</li>
<li><strong>_totalMapsWidth</strong> - this is the X offset we want to create the map at (total width of all maps we've created so far).</li>
<li><strong>0</strong> - this is the Y offset for the tilemap.  Since we're only scrolling horizontally, this is set to 0.</li>
<li><strong>true </strong>- whether or not to parse sprites (if set to false, only the tilemap will be created, no other sprites/enemies/etc.)</li>
<li><strong>false </strong>- whether or not to recycle maps.  This tells FlashPunk whether it should use remove() or recycle() when a map goes off screen.  Theoretically using recycle() should be more efficient, but I was getting mixed results, so I set the default to false.</li>
</ul>
<p>Ok, let's take a look at the actual <strong>TilemapGeneratorEntity</strong> class.  Some of this will be redundant from the list above, but since this is a custom class, I want to explain it in detail:</p>
<pre class="brush:as3;first-line:42">public function TilemapGeneratorEntity($xmlAsset:*= null, $tilesetAsset:*= null, $layerName:String = null, $collisionType:String = null, $x:Number = 0.0, $y:Number = 0.0, $parseSprites:Boolean = true, $recycleMaps:Boolean = true )
		{
			_xmlAsset = $xmlAsset;
			_tilesetAsset = $tilesetAsset;
			_layerName = $layerName;
			_collisionType = $collisionType;
			_x = $x;
			_y = $y;
			_parseSprites = $parseSprites;
			_recycleMaps = $recycleMaps;
		}</pre>
<p>So the constructor function isn't doing anything other than setting a bunch of variables that we pass into the constructor.  Technically all of the class variables (anything that starts with an _underscore) should be private, but for simplicity I left them all as public.  Notice that this class is actually extending the FlashPunk Entity class.  Therefore, there are a few methods that will be called automatically for us:</p>
<h2>added() method:</h2>
<pre class="brush:as3;first-line:54">		override public function added():void
		{
			/* DEVELOPER NOTE:
			 * all of this information is done within the added() function,
			 * because using FP.world.create() requires passing the class
			 * with no paramters.  So we call a new instance with default
			 * constructor paramters, then set each variable directly
			 * from wherever FP.world.add() was called.
			*/

			// let's focus on the map layer, based on the layer name that was passed in
			var _tileLayer:XMLList = _xmlAsset.tiles.(@layer == _layerName);</pre>
<p>As noted in the comments starting on <strong>line 56</strong>, the reason most of the code in this class is within the <strong>added()</strong> method instead of the constructor, is because FlashPunk does not allow the passing of any parameters when using <a href="http://flashpunk.net/docs/net/flashpunk/World.html#create()">FP.world.create()</a>.  So with that explained, move down to <strong>line 65</strong> where the code actually starts.</p>
<pre class="brush:as3;first-line:65">var _tileLayer:XMLList = _xmlAsset.tiles.(@layer == _layerName);</pre>
<p>If you remember, <strong>_xmlAsset</strong> contains a reference to <strong>Assets.LEVEL_TEMPLATES_XML</strong>, from our <strong>Assets.as</strong> file.  Let's look at that real quick:</p>
<h2>Assets.as</h2>
<pre class="brush:as3;first-line:38">		// XML Assets
		[Embed(source = '../assets/levels/level_templates.xml', mimeType="application/octet-stream")]
		public static const LEVEL_TEMPLATES:Class;

		// lets convert the asset into an XML now, so we only have to do it once
		public static const LEVEL_TEMPLATES_XML:XML = new XML(new LEVEL_TEMPLATES);

		// and while we're at it, let's get the total count of templates too
		public static const LEVEL_TEMPLATES_COUNT:Number = LEVEL_TEMPLATES_XML.tiles.length();</pre>
<p>First, on <strong>line 39</strong> you can see we're embedding the XML file we got from DAME using the  meta-tag (<a href="http://livedocs.adobe.com/flex/3/html/embed_3.html#207672">more details on that here</a>).  This means that once we build our SWF file, everything will be embedded within.  The final SWF file will be much bigger, however once it's loaded, there won't be anything else to worry about (waiting for XML, audio, images, etc. to load).</p>
<p>Then, on <strong>line 43</strong> we create a static constant with the actual data from the file.  If we d0n't do this, we won't be able to load the XML since it's still being recognized as a <strong>Class </strong>object (we need it to be an <strong>XML </strong>object).  There are lots of other ways to load XML, this was just my approach.</p>
<p>Finally, since we've already taken the time to put all of the XML data into a constant, why not create a constant for the total number of level templates (the number of &lt;tiles&gt; tags in the XML file) as well?  That's what we do on <strong>line 46</strong>, creating a constant for <strong>LEVEL_TEMPLATES_COUNT</strong>.</p>
<p>With that explained, let's go back to the tilemap generator</p>
<h2>TilemapGeneratorEntity.as:</h2>
<pre class="brush:as3;first-line:67">			// we set width/height/etc here for convenience, but we can't rely on having
			// the information instantly, which is why mapLayerWidth() getter function
			// was created (bottom).  It would be replaced with a width() getter function.
			_width = _tileLayer.@width;
			_height = _tileLayer.@height;
			_tileWidth = _tileLayer.@tileWidth;
			_tileHeight = _tileLayer.@tileHeight;</pre>
<p>On <strong>lines 70-71</strong>, we store the width and height of the entire Tilemap that's being generated which is being pulled from the <strong>width</strong> attribute in the &lt;tiles&gt; tag in our embedded XML file.  Accessing this <strong>_width </strong>variable directly isn't reliable, so a <strong>mapLayerWidth()</strong> getter function was added as mentioned in the comments.  More on that in a second.  Next, on <strong>lines 72-73</strong>, we simple store the height and width of our tiles in this tilemap (in this example, it's 32 x 32 pixels).</p>
<p>Now let's give all this information to <strong>FlashPunk</strong>, and setup the Tilemap and Grid classes so that they will do most of the hard work:</p>
<pre class="brush:as3;first-line:75">// Build the empty tilemap and grid
			var _tiles:Tilemap = new Tilemap(_tilesetAsset, _width, _height, _tileWidth, _tileHeight);
			var _grid:Grid = new Grid(_width, _height, _tileWidth, _tileHeight);
			mask = _grid;</pre>
<p>When creating the new Tilemap, just pass in the image asset (<strong>Assets.BG_TILES</strong>), along with the width and height of the tilemap, along with the width and height of the tiles.  Next, we create a new instance of the <a href="http://flashpunk.net/docs/net/flashpunk/masks/Grid.html">Grid</a> class, which is basically a helper for doing efficient collision detection against a Tilemap.  The last line (<strong>78</strong>) in this block of code is to set the <strong>mask</strong> (for collision detection) of our <strong>TilemapGeneratorEntity </strong>to the Grid that was just created.</p>
<p>About half way through this class, let's keep up the pace.  Our Tilemap and Grid is setup (width, height), but there's nothing in them yet.  Let's move on to actually creating the tilemap from the XML data:</p>
<pre class="brush:as3;first-line:80">// parse the map layer xml
			for each(var tile:XML in _tileLayer.tile)
			{

				// add the tile to the tilemap
				_tiles.setTile(
					(tile.@x / _tileWidth),
					tile.@y / _tileHeight,
					_tiles.getIndex(
						tile.@tx / _tileWidth, tile.@ty / _tileHeight
					)
				);
				// add the tile to the grid for collision detection
				_grid.setTile(
					tile.@x / _tileWidth,
					tile.@y / _tileHeight
				);
			}</pre>
<p>Lines <strong>81-97</strong> run a loop which parses through each tile in our map (e.g. each of the &lt;tile&gt; tags within the current &lt;tiles&gt; tag).  On<strong> line 85</strong>, we set the tile within the tilemap.  Here is an illustration to explain what the <a href="http://flashpunk.net/docs/net/flashpunk/graphics/Tilemap.html#setTile()">setTile()</a> method is doing.</p>
<p>This is an example of a &lt;tile&gt; node:</p>
<pre class="brush:xml;first-line:3">&lt;tile tx="96" ty="0" x="256" y="0"/&gt;</pre>
<p>Explanation of each attribute:</p>
<ul>
<li><strong>tx/ty</strong> - This is the x/y position of the tile <strong>within the tileset (image asset).</strong></li>
<li><strong>x/y</strong> - this is the position of the tile within the <strong>Tilemap </strong>we are creating.</li>
</ul>
<p>So if our <strong>tx </strong>is <strong>96</strong>, and <strong>ty</strong> is <strong>0</strong>, then <strong>lines 85-91</strong> for this tile would be:</p>
<pre class="brush:as3;first-line:81">_tiles.setTile(
					(256 / 32),
					0 / 32,
					_tiles.getIndex(
						96 / 32, 0 / 32
					)
				);</pre>
<p>And reducing this further:</p>
<pre class="brush:as3;first-line:81">_tiles.setTile(8, 0, _tiles.getIndex(3, 0));</pre>
<p>We're telling FlashPunk that the coordinates (8,0) within our <strong>Tilemap </strong>(which is at 256, 0 in pixels) should be represented by the graphic at (3,0), which is the fourth tile in the array (since 0 counts as the first one).  See the image below to see what's happening here.  The grid represents a small section in the top left corner of our map.  The tileset below the grid shows the first seven items in our array of tiles to select from.</p>
<p><img class="alignnone size-full wp-image-866" title="tilemap-example" src="http://producerism.com/wp-content/uploads/2011/05/tilemap-example.png" alt="" width="600" height="250" /></p>
<p>Here is another illustration of how all of the XML attributes correlate to the settings in DAME, and the Tilemap we are creating.</p>
<p><img class="alignnone size-full wp-image-882" title="xml-tilemap-illustration" src="http://producerism.com/wp-content/uploads/2011/05/xml-tilemap-illustration1.png" alt="" width="715" height="308" /></p>
<p>Now that the graphics for the tilemap have been placed, we need to setup collision detection using our <a href="http://flashpunk.net/docs/net/flashpunk/masks/Grid.html">Grid</a> (which was set as our Entity's <a href="http://flashpunk.net/docs/net/flashpunk/Entity.html#mask">mask</a>).  You can think of the mask as a simple black and white (or transparent) image that represents our collidable "hit" area.</p>
<p><img class="alignnone size-full wp-image-870" title="mask" src="http://producerism.com/wp-content/uploads/2011/05/mask.png" alt="" width="650" height="261" /></p>
<p>Since our tilemap image and mask have been created, we could technically return all of this and start our game.  However, DAME also allows the placement of sprites in maps - which don't need to be assigned to specific tiles, but rather any pixel values we want.  This is a really cool feature that the next block of code makes great use of.  Let's take it step by step, since there are a few levels of logic to consider.</p>
<p><strong>Step 1</strong> - check to see if we should even bother to parse the sprites in this instance.</p>
<pre class="brush:as3;first-line:99">			// only add sprites if flagged to do so
			if (_parseSprites)
			{</pre>
<p><strong>Step 2</strong> - first we use E4X to search through the XML data for the &lt;sprites&gt; tag which has the layer attribute of _layerName (e.g. "template1").  Then we use a <strong>for each</strong> statement to parse through them.</p>
<pre class="brush:as3;first-line:102">				// now let's focus on any sprite layer with the same name as the map layer
				var _spriteLayer:XMLList = _xmlAsset.sprites.(@layer == _layerName);

				for each(var sprite:XML in _spriteLayer.sprite)
				{</pre>
<p><strong>Step 3</strong> - check to see how many sprites we should spawn, based on the attribute <strong>spawnAmount </strong>in our XML file.  If it's undefined, the default is set to 1.</p>
<pre class="brush:as3;first-line:108">var spawnAmount:uint = (sprite.@spawnAmount == undefined) /? 1 : uint(sprite.@spawnAmount);</pre>
<p><strong>Step 4</strong> - now we set a loop for creating sprites, based on our <strong>spawnAmount.</strong></p>
<pre class="brush:as3;first-line:110">					// create the sprites
					for (var spawnCounter:uint = 0; spawnCounter &lt; spawnAmount; spawnCounter++)
					{</pre>
<p><strong>Step 5</strong> - check the XML attribute spriteClass, so see what type of sprite we should create.  If the class doesn't exist, then we just trace out an error and continue.  In testing, it would make sense to trigger an actual error here.</p>
<pre class="brush:as3;first-line:113">						// since we're referencing classes dynamically, we can't be sure they actually exist
						try
						{
							var spriteClass:Class = getDefinitionByName(String(sprite.@className)) as Class;
						} catch (err:Error)
						{
							trace(String(sprite.@className) + " class not found!");
							continue;
						}</pre>
<p>Let's stop for just a second here, because this technique is using a method I wasn't very familiar with.</p>
<h2>getDefinitionByName</h2>
<p>If you are already familiar with the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#getDefinitionByName()">getDefinitionByName </a>method, feel free to skip ahead.  This is a useful function that allows Flash to instantiate a class at run-time, which hasn't been imported in code.  To put it another way, normally if you want to use a <strong>TextField </strong>in your application, you need to call <strong>import flash.text.TextField;</strong> at the top of your code.  Using getDefinitionByName you wouldn't have to import anything - instead you could call getDefinitionByName("flash.text.TextField").  In our case, it's more like getDefinitionByName("FlyingHorse").  The reason that this is useful, is that we can just assign all of our classes in DAME, and then create the corresponding actionscript classes afterwards.</p>
<p>One of the gotchas of using this method, is that there needs to be a reference of some kind to all of these classes in your code somewhere.  I just added a list of them to the end of <strong>Assets.as:</strong></p>
<pre class="brush:as3;first-line:48">		// To avoid errors from the compiler when calling getDefinitionByName
		// just list all of the classes that are not otherwise referenced in code:
		Balloon;
		Cloud;
		FlyingHorse;
		FlyingPig;
		UFO;
		Zeppelin;</pre>
<p><strong>NOTE:</strong> If you do not reference the classes you intend to use via getDefinitionByName somewhere in your code, you will get the following error:</p>
<p><span style="color: #ff0000;">[Fault] exception, information=<strong>ReferenceError: Error #1065: Variable Balloon is not defined.</strong></span> In this case, we tried calling getDefinitionByName("Balloon").</p>
<h2>Back to TilemapGeneratorEntity.as:</h2>
<p>Side-comment over, hopefully that was useful.  At this point, we have decided if a sprite needs to be created, and if so, which one.  Now let's actually create it, and place it within the game according to our level design in DAME.</p>
<pre class="brush:as3;first-line:123">						// by default, we're using FP.world.create(), and assuming that entities will be recycled
						// by passing false as the second paramter, we tell FlashPunk not to add the entity yet
						var spriteEntity:Entity = FP.world.create(spriteClass, false);</pre>
<p>On line 125, we simply create our <strong>spriteClass </strong>(e.g. "FlyingHorse," Balloon," etc.) within the world using FP.world.create().  As it says in the comments, we pass <strong>false </strong>as the second parameter, which tells FlashPunk to create the sprite, but not to add it yet (same as creating a new <strong>TextField </strong>before adding it to the stage with <strong>addChild</strong>).  This allows us to place the sprite according to our XML data:</p>
<pre class="brush:as3;first-line:127">						// set the sprite position, offset by the map layer's x/y positions (this is a DAME workaround)
						if (sprite.@spawnShape == undefined)
						{
							spriteEntity.x = (Number(sprite.@x) - Number(_tileLayer.@x)) + _x;
							spriteEntity.y = (Number(sprite.@y) - Number(_tileLayer.@y)) + _y;
						}</pre>
<p>If you remember back in <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-2/">part 2</a>, I mentioned that we would also implement the shape feature of DAME, so that we could randomly spawn new objects within the area of that shape.  <strong>Line 128</strong> is where we check to see if that spawnShape has been assigned.  If not, we just place the sprite according to the <strong>x</strong> and <strong>y</strong> attributes in the &lt;sprite&gt; node.  So that's what happens if <strong>spawnShape </strong>is <strong>undefined</strong>.  This is what happens if it <em>has </em>been defined:</p>
<pre class="brush:as3;first-line:133">						else
						{
							// if spawnShape was defined, use the area to generate random placement
							var spawnShape:XMLList = _xmlAsset.shapes.shape.(@guid == sprite.@spawnShape);
							var spawnMinX:Number = Number(spawnShape.@x) + Number(sprite.@width) / 2;
							var spawnMaxX:Number = Number(spawnShape.@x) + Number(spawnShape.@width) - Number(sprite.@width) / 2;
							var spawnMinY:Number = Number(spawnShape.@y) + Number(sprite.@height) / 2;
							var spawnMaxY:Number = Number(spawnShape.@y) + Number(spawnShape.@height) - Number(sprite.@height) / 2;

							spriteEntity.x = int((Math.random() * (spawnMaxX - spawnMinX + 1) + spawnMinX - int(_tileLayer.@x)) + _x);
							spriteEntity.y = int((Math.random() * (spawnMaxY - spawnMinY + 1) + spawnMinY - int(_tileLayer.@y)) + _y);
						}</pre>
<p>First, on <strong>line 136</strong>, we find the shape that was passed in as our <strong>spawnShape</strong>.  Then, we find the bounds of the shape (left, right, top, bottom) while taking the size of the sprite into account.  Finally, on <strong>lines 142-143</strong>, we randomly place the sprite somewhere within those bounds.  And the last step in this big loop is to add the sprite to our world (since it was already created, then positioned, now we display it).</p>
<pre class="brush:as3;first-line:146">// we've already created the entity, now add it
						FP.world.add(spriteEntity);</pre>
<p>That's the last thing that happens in each iteration of the loop that was started back on <strong>line 100</strong>.  Once all of the sprites have been parsed, we're ready to create the tilemap, set the collision group, and then add the actual tilemap to the world.</p>
<pre class="brush:as3;first-line:153">			// set the graphic to the tilemap that was just created from xml
			graphic = _tiles;
			x = _x;
			y = _y;
			type = _collisionType;

			super.added();
		}</pre>
<p>So close to the end of this class!  I imagine it's been a process reading this far.  There is one other function that will be called automatically by FlashPunk (the biggest hint is that this is an <strong>override</strong> function).</p>
<h2>update()</h2>
<pre class="brush:as3;first-line:162">		override public function update():void
		{
			// once the tilemap goes off camera, we discard it
			if (x &lt; FP.camera.x - width)
			{
				if (_recycleMaps)
				{
					// recycling tells FlashPunk to re-use this entity
					// when calling FP.world.create() on the same class
					FP.world.recycle(this);
				} else {
					// removing tells FlashPunk to destroy the entity
					// this leaves it up to flash's garbage collection
					FP.world.remove(this);
				}
			}

			super.update();
		}</pre>
<p>This function is called every frame, and simply checks to see if the position of the tilemap is off the screen.  If so, we either recycle or remove the map from the world, depending on our <strong>_recycleMaps</strong> value (default is <strong>false</strong>, which uses <strong>FP.world.remove</strong>).  Last but not least, let's cover the aforementioned "getter" method.</p>
<h2>get mapLayerWidth()</h2>
<pre class="brush:as3;first-line:182">		// since we can't rely on _width property to have the information right away,
		// this getter function will retrieve the info directly from the xml asset
		public function get mapLayerWidth():int { return int(_xmlAsset.tiles.(@layer == _layerName).@width); }</pre>
<p>This is the final code in the TilemapGeneratorEntity class.  As mentioned before, we can't rely on the _width value of our TilemapGeneratorEntity to be accurate until all of this information has been parsed, so we create a helper function which checks the XML data for this value directly (again, using E4X).</p>
<p>Well, that concludes part 6 of this tutorial.  The next part we will cover the FlyingEntity class, which all of our enemies extend (FlyingPig, FlyingHorse, etc.).  Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: Develop in Corona SDK on Windows</title>
		<link>http://producerism.com/blog/how-to-develop-in-corona-sdk-on-windows/</link>
		<comments>http://producerism.com/blog/how-to-develop-in-corona-sdk-on-windows/#comments</comments>
		<pubDate>Sun, 01 May 2011 20:26:46 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=824</guid>
		<description><![CDATA[9/3/2011 Update: Added some changes to the process, updated screenshots, and disclaimers regarding Java JDK v6 and the new Corona requirement of Android OS 2.2+ and ARMV7.  I've expanded on the hardware shortcoming and a few other annoyances and issues in a new post: Where Corona SDK Falls Flat. Developing mobile apps and games for [...]]]></description>
			<content:encoded><![CDATA[<p><strong>9/3/2011 Update:</strong> Added some changes to the process, updated screenshots, and disclaimers regarding Java JDK v6 and the new Corona requirement of Android OS 2.2+ and ARMV7.  I've expanded on the hardware shortcoming and a few other annoyances and issues in a new post: <a href="http://producerism.com/blog/where-corona-sdk-falls-flat/">Where Corona SDK Falls Flat</a>.</p>
<p>Developing mobile apps and games for both Android and iOS (iPhone/iPad/iTouch) is not the easiest thing in the world.  For iOS, the main option is to develop in Objective-C with Xcode in OSX.  However, if you want to develop for Android, there are a few more options - although most of them still require recoding when porting to iOS.  One of the biggest options for cross-device development is the Adobe iOS Packager for Flash/Flex/AIR.  All the code can be done in Actionscript 3, and then deployed to either device (and for free!).  The downside of this, is that without serious tweaking and compromise, the framerate on games is subpar.  In time, I'm sure Adobe will smooth things out, however as it stands, it's very limiting to work with the packager.  Enter the Corona SDK:</p>
<p><img class="alignnone size-full wp-image-825" title="corona" src="http://producerism.com/wp-content/uploads/2011/05/corona_header.jpg" alt="" width="650" height="130" /><br />
Corona SDK is basically a Lua library that wraps both Android and iOS functions into a single API.  In this article, I will show you how to setup an environment for developing with Corona, complete with code auto-completion, basic error checking, and an example of a box2d physics app running in both the simulator and an Android device.  All in less than 2 minutes.  Haha ok, maybe not that quick, but seriously, it takes about 15 minutes to be up and running, since there are a few things you will need to download and install.  Then, the actual box2d app will be<em> less than 10 lines of code</em>.<span id="more-824"></span></p>
<h2>Requirements</h2>
<p>Before we start, you will need to download these four things (don't worry, they are all free).</p>
<ol>
<li><a href="http://code.google.com/p/luaforwindows/">Lua for Windows</a></li>
<li><a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u27-download-440405.html">Java SDK v6 x86 (32bit)</a> (note: <strong>version 6</strong>, <em>not</em> the newest which is <em>version 7</em>. <a href="http://download.oracle.com/otn-pub/java/jdk/6u27-b07/jdk-6u27-windows-i586.exe">Here is a direct link</a>)</li>
<li><a href="http://www.anscamobile.com/corona/">Corona SDK</a></li>
<li><a href="http://www.jetbrains.com/idea/free_java_ide.html">IntelliJ IDEA (Community Edition)</a></li>
<li><a href="https://bitbucket.org/sylvanaar2/idlua-sdk-corona/wiki/Home">Corona API</a> (by sylvanaar2)</li>
<li>(Optional) Here is the project file for this tutorial: <a href="http://producerism.com/wp-content/uploads/2011/05/HelloCorona.zip">HelloCorona.zip</a></li>
<li>If testing on an Android device, <a href="http://developer.anscamobile.com/forum/2011/04/16/last-daily-build-armv6-support">minimum specs</a> are Android OS <strong>2.2+</strong>, and <strong>ARMV7</strong>)</li>
</ol>
<h2>Installation</h2>
<p>This is all pretty easy.  First, install Lua, Corona SDK, and IntelliJ IDEA using recommended settings (or custom, if you want to go rogue).  The Corona API you downloaded will be a .zip file.  Just extract that somewhere (e.g. <strong>c:\sdks\sylvanaar2-idlua-sdk-corona</strong>).  If you're curious, there's only three files inside this folder: <strong>api-reference.html</strong>, <strong>corona_api.doclua</strong>, and <strong>coronoa_api.lua</strong>.</p>
<p>Now that everything is installed, feel free to open up the Corona simulator to test out some of the provided examples:</p>
<p><img class="alignnone size-full wp-image-985" title="corona_splash" src="http://producerism.com/wp-content/uploads/2011/05/corona_splash.jpg" alt="" width="623" height="400" /></p>
<p>All of these examples are stored in the Corona SDK Installation folder (e.g. <strong>C:\Program Files (x86)\Ansca\Corona SDK\Sample Code</strong>).  The main file for each project is <strong>main.lua</strong>.  Of course, this article is about developing with Corona, so let's get to it.</p>
<h2>Setting up IntelliJ IDEA for Lua and Corona SDK</h2>
<p>We need to enable Lua support first, so launch IntelliJ IDEA and click on <strong>File -&gt; Settings</strong>:</p>
<p><img class="alignnone size-full wp-image-829" title="idea_settings" src="http://producerism.com/wp-content/uploads/2011/05/idea_settings.jpg" alt="" width="249" height="241" /></p>
<p>When the Settings window comes up, find the <strong>Plugins </strong>option inside of the left column, and then find the <strong>Lua </strong>plugin under the <strong>Available </strong>tab on the right.  Right click on the entry, and select <strong>Install Plugin</strong>.</p>
<p><a href="http://producerism.com/wp-content/uploads/2011/05/idea_lua_plugin.jpg"><img class="alignnone size-full wp-image-986" title="download_lua_plugin" src="http://producerism.com/wp-content/uploads/2011/05/download_lua_plugin.jpg" alt="" width="743" height="325" /></a></p>
<p>Great, Lua is now supported in IDEA, complete with syntax highlighting and lots of other features.  Let's start on a Corona project.  Create a <strong>new project</strong>.</p>
<p><img class="alignnone size-full wp-image-828" title="idea_new_project" src="http://producerism.com/wp-content/uploads/2011/05/idea_new_project.jpg" alt="" width="551" height="251" /></p>
<p>Notice that Kahlua is listed, but we want to add our own.  Click on the <strong>Configure...</strong> button.  In the top left corner of the <strong>Configure SDK</strong> window, click on the plus sign, and then select <strong>Lua SDK</strong> from the menu.</p>
<p><img class="alignnone size-full wp-image-831" title="idea_config_lua" src="http://producerism.com/wp-content/uploads/2011/05/idea_config_lua.jpg" alt="" width="593" height="323" /></p>
<p>Once you select Lua SDK from the menu, you will be asked to provide the location of your Lua folder.  (e.g. <strong>C:\Program Files (x86)\Lua\5.1</strong>)</p>
<p><img class="alignnone size-full wp-image-832" title="idea_config_lua-2" src="http://producerism.com/wp-content/uploads/2011/05/idea_config_lua-2.jpg" alt="" width="315" height="324" /></p>
<p>Almost done.  You can see that <strong>Lua 5.1.x</strong> is now listed on the left under Kahlua.  Before we finish, let's add the <strong>Corona API</strong> we downloaded and extracted.  Click on the <strong>Add...</strong> button.</p>
<p><img class="alignnone size-full wp-image-833" title="idea_config_lua-3" src="http://producerism.com/wp-content/uploads/2011/05/idea_config_lua-3.jpg" alt="" width="593" height="323" /></p>
<p>Now find the folder where you extracted the Corona API to (e.g. <strong>c:\sdks\sylvanaar2-idlua-sdk-corona</strong>).</p>
<p><img class="alignnone size-full wp-image-834" title="idea_config_lua-4" src="http://producerism.com/wp-content/uploads/2011/05/idea_config_lua-4.jpg" alt="" width="593" height="323" /></p>
<p>That's it!  Click <strong>OK</strong> until you get back to the <strong>New Project</strong> window, then make sure <strong>Lua 5.1.x</strong> is selected before clicking <strong>Finish</strong>.</p>
<p><img class="alignnone size-full wp-image-835" title="idea_config_lua-finish" src="http://producerism.com/wp-content/uploads/2011/05/idea_config_lua-finish.jpg" alt="" width="552" height="252" /></p>
<p><strong>(Update 9/11/2011) - One more step...</strong></p>
<p>To fully enable the code-completion, go back to File -&gt; Settings:</p>
<p><img class="alignnone size-full wp-image-829" title="idea_settings" src="http://producerism.com/wp-content/uploads/2011/05/idea_settings.jpg" alt="" width="249" height="241" /></p>
<p>Then find "<strong>Lua</strong>" on the list under "<strong>IDE Settings</strong>."  There is a checkbox to "<strong>Add additional completions</strong>."  Make sure you check that box and hit ok.</p>
<p><img class="alignnone size-full wp-image-1054" title="lua-additional-completions" src="http://producerism.com/wp-content/uploads/2011/05/lua-additional-completions.jpg" alt="" width="660" height="357" /></p>
<p>Now that all of that is done, we won't have to do it again!  Now you really can create a new app within a few minutes since the tedious setup is done with.  At this point, you should have your new <strong>HelloCorona </strong>project waiting for you.  Plus, you will have some great features like syntax checking and auto-complete:</p>
<p><img class="alignnone size-full wp-image-839" title="idea_autocomplete" src="http://producerism.com/wp-content/uploads/2011/05/idea_autocomplete.jpg" alt="" width="351" height="285" /></p>
<h2>Starting a new Corona SDK project</h2>
<p>Each Corona project is made up of at least two files: <strong>config.lua</strong> and <strong>main.lua</strong> (you will have to create these yourself).  Here's a screenshot of what this project looks like (2 lua files, and 3 images).  <strong>Important Note:</strong> Notice that all of the images and scripts are in the same folder.  If you try putting your assets into subfolders, the Corona Simulator will work as expected, but when you deploy to your mobile device, the app will hang.  It took me quite a while to figure that out on my own.</p>
<p><img class="alignnone size-full wp-image-851" title="corona_project_files" src="http://producerism.com/wp-content/uploads/2011/05/corona_project_files1.jpg" alt="" width="650" height="405" /></p>
<p><strong>config.lua:</strong></p>
<pre class="brush: lua">application =
{
	content =
	{
		width = 320,
		height = 480,
		scale = "zoomEven"
	}
}</pre>
<p>Pretty straightforward - we create an object (in Lua it's a table) for application, and inside that, another object for content settings.  The scale is set to "zoomEven" which basically scaled the content while keeping the same aspect ratio.  Here is a <a href="http://developer.anscamobile.com/content/configuring-projects">complete list of options for config.lua</a>, since this is just a very basic example.  Easy, right?  So let's look at the code for implementing box2d.</p>
<p><strong>main.lua:</strong></p>
<pre class="brush: lua">local background = display.newImage("background.png")

local ground = display.newImage("ground.png")
ground.y = display.contentHeight - ground.height / 2

local crate = display.newImage("crate.png")
crate.x = display.contentCenterX</pre>
<p><strong>Line 1</strong> both loads and displays the background image (<strong>background.png</strong>) in a single call.  It's the first thing we add to the screen, since it's the background.  Everything added now will be on top of it (higher z-index).</p>
<p><strong>Line 3</strong> adds the ground image (<strong>ground.png</strong>) and then line 4 places it at the bottom of the screen.  This "<strong>display</strong>" object we keep referring to is analogous to the stage in flash.  It also has similar properties as a flash Sprite, like width, height, etc.  Here is a <a href="http://developer.anscamobile.com/reference/index/common-properties">complete list of the properties each display object has</a> in Corona SDK.  <strong>Line 6</strong> is pretty similar, except we place the <strong>crate.x </strong>at <strong>display.contentCenterX </strong>(which is the same as stage.stageWidth / 2 in Actionscript 3).</p>
<pre class="brush: lua; first-line:9">local physics = require( "physics" )
physics.start()
physics.addBody(ground, "static")
physics.addBody(crate)</pre>
<p>On <strong>line 9</strong>, we include p<strong>hysics</strong>, which is Corona SDK's wrapper for box2d  (read more about it in the <a href="http://developer.anscamobile.com/content/game-edition-box2d-physics-engine">guide </a>and <a href="http://developer.anscamobile.com/reference/index/physics-engine">api</a>).  Then, on <strong>line 10</strong> we start the physics engine, which automatically sets gravity to (0, 9.8) and updates at the frame rate Corona is set to (default is 30 fps).</p>
<p><strong>Line 11</strong> tells the <strong>physics </strong>to recognize the <strong>ground </strong>object as a physical body, and sets it to "<strong>static</strong>" which means it will be stationary.</p>
<p><strong>Line 12</strong> adds the <strong>crate </strong>as another physics body, but uses the default type of "<strong>dynamic</strong>" which means it can move.</p>
<h2>Running the project</h2>
<p>All of the code for this example is done!  A total of <em>3 images</em> and only <em>9 lines</em> of code (10 if you include <strong>config.lua</strong>, which could all be on a single line).  There is one last thing to setup before we can run our project.  We need to edit the run configuration of the project, so first click on the drop-down menu next to the run button, and select "<strong>Edit Configurations</strong>."</p>
<p><img class="alignnone size-full wp-image-915" title="edit_config" src="http://producerism.com/wp-content/uploads/2011/05/edit_config.png" alt="" width="201" height="127" /></p>
<p>In the Run/Debug Configurations window that pops up, set the Lua interpreter to the Corona Simulator.exe file, otherwise you will get errors when you try to run your code through the default Lua interpreter:</p>
<p><img class="alignnone size-full wp-image-916" title="interpret" src="http://producerism.com/wp-content/uploads/2011/05/interpret.png" alt="" width="750" height="582" /></p>
<p>Now just click on the Run button, or go to the <strong><span style="text-decoration: underline;">R</span>un -&gt; Run (Shift + F10)</strong> menu in IntelliJ IDEA.</p>
<p><img class="alignnone size-full wp-image-840" title="idea_run" src="http://producerism.com/wp-content/uploads/2011/05/idea_run.jpg" alt="" width="600" height="85" /></p>
<p>A command prompt will show up, letting you know that IDEA is launching your <strong>main.lua</strong> file with the Corona Simulator (using <strong>config.lua</strong> for display settings).</p>
<p><img class="alignnone size-full wp-image-841" title="corona_simulator_prompt" src="http://producerism.com/wp-content/uploads/2011/05/corona_simulator_prompt.jpg" alt="" width="499" height="159" /></p>
<p>You will also see the Simulator show up, where you can select various phones in the menu.</p>
<p><img class="alignnone size-full wp-image-842" title="corona_simulator" src="http://producerism.com/wp-content/uploads/2011/05/corona_simulator.jpg" alt="" width="241" height="400" /></p>
<p>Speaking of the Simulator window, now that we can see our code in action, it looks pretty good.. but how will it look on an actual Android device?  Let's find out right now!  Click on the File -&gt; Build menu, and fill out your Package name, Target OS, and the Save to Folder.  I have mine building directly into my <a href="http://db.tt/PjNfYEh">Dropbox </a>folder, since I also have Dropbox installed on my Android.  This means that as soon as I'm done building, I just open Dropbox on my phone and install the .apk file.  It really couldn't be any easier.</p>
<p><img class="alignnone size-full wp-image-844" title="corona_build" src="http://producerism.com/wp-content/uploads/2011/05/corona_build.jpg" alt="" width="480" height="365" /></p>
<p>After you click the <strong>Build </strong>button, Corona SDK will actually connect to their build servers and generate the apk there.  Once the build process is done, the .apk gets sent back, and copied to your <strong>Save to Folder</strong>.  I imagine the same process could be done for iOS eventually, but that's not a feature on the current <a href="http://www.anscamobile.com/resources/roadmap/">Corona SDK roadmap</a>.</p>
<p>So, that's it!  You now have IntelliJ IDEA setup for Lua and Corona development.  All you need to do is create a new project, add your assets, <strong>config.lua</strong> and <strong>main.lua</strong> files, and hit run.  Once it looks good, just build it!</p>
<h2>Alternate Way of Launching Simulator</h2>
<p><strong>Update 04/24/2012 - </strong>The process outlined above makes use of the built-in launching feature of IntelliJ.  However, there is a much better solution to launch the Corona SDK simulator from within IntelliJ IDEA, which allows the output window to show line breaks.  This method makes debugging much easier, and it's the method I'm using, instead of hitting the "Run" button.  First, copy the following code, paste it into a new text file, and save the file as "<strong>CoronaLauncher.vbs</strong>"</p>
<p><strong>Note:</strong> This updated section (04/24/2012) is using IntelliJ IDEA 11.1, and some of the dialogs have changed slightly.  If you are using the older IntelliJ IDEA, all of these settings are in the same places, but the buttons/checkboxes may have been rearranged.  Feel free to comment if you need help setting up.</p>
<p><strong>CoronaLauncher.vbs</strong></p>
<p><strong>Note:</strong> Lines <strong>12</strong> and <strong>21</strong> should point to your <strong>Corona Simulator.exe</strong> file.  If you are running Windows 64-bit, this will probably need to be changed to C:\Program Files<em> (x86)</em>\Ansca\...</p>
<pre class="brush:vb; highlight: [12, 21]">Set WshShell = WScript.CreateObject ("WScript.Shell")
Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process")

'Check if Corona is already running
For Each objProcess in colProcessList
If objProcess.name = "Corona Simulator.exe" then
vFound = True
End if
Next
If vFound = True then
'If Corona is already running, then switch to it and refresh
WshShell.AppActivate "C:\Program Files\Ansca\Corona SDK\Corona Simulator.exe"
WScript.Sleep 100
WshShell.SendKeys "{ESC}"
WScript.Sleep 100
WshShell.AppActivate "Corona Simulator"
WScript.Sleep 200
WshShell.SendKeys "^r"
Else
'If Corona isn't running, launch it with your main.lua
WshShell.Run """C:\Program Files\Ansca\Corona SDK\Corona Simulator.exe """ &amp; WScript.Arguments(0)
End If</pre>
<p>Once you've created a CoronaLauncher.vbs file with the code above, open up IntelliJ IDEA and under the <strong>File</strong> menu, select <strong>Settings</strong>.</p>
<p><img class="alignnone size-full wp-image-1183" title="Settings" src="http://producerism.com/wp-content/uploads/2011/05/StoryTouch-D_dropbox-ideasDropboxprojectsStoryTouchStoryTouch-Story_2012-04-24_13-45-15.png" alt="" width="473" height="432" /></p>
<p>In the settings window that comes up, find the "<strong>External Tools</strong>" section.  It will probably be empty - so click on the <strong>add</strong> button to create a new tool.</p>
<p><img class="alignnone size-full wp-image-1184" title="External Tools empty" src="http://producerism.com/wp-content/uploads/2011/05/Settings_2012-04-24_13-52-04.png" alt="" width="593" height="371" /></p>
<p>In the Edit Tool window that pops up, enter the following values.  Pay attention to the <strong>Parameters:</strong> field, and make sure you update the value so it points to where you saved the <strong>CoronaLauncher.vbs</strong> file created earlier.  Also, make sure that "<strong>Open console</strong>" is<strong> not checked.</strong></p>
<p><img class="alignnone size-full wp-image-1185" title="Edit Tool" src="http://producerism.com/wp-content/uploads/2011/05/Edit-Tool_2012-04-24_13-54-34.png" alt="" width="588" height="416" /></p>
<p>After hitting the OK button to save, you should now see it listed to confirm you're on the right track.</p>
<p><img class="alignnone size-full wp-image-1186" title="Tool Confirmation" src="http://producerism.com/wp-content/uploads/2011/05/Settings_2012-04-24_13-54-42.png" alt="" width="593" height="371" /></p>
<p>Hit OK to save this change, and then open up the Settings window again.  (Note: For me, when I hit "Apply" instead of "OK" the next step couldn't be done.  So just to be safe, hit OK.)  When the Settings window comes up, scroll down to the section for "<strong>Keymap</strong>."  Under the External Tools folder, the Simulator should now be listed.  Right click on the entry, and select "<strong>Add Keyboard Shortcut</strong>"</p>
<p><img class="alignnone size-full wp-image-1187" title="Keymap" src="http://producerism.com/wp-content/uploads/2011/05/Settings_2012-04-24_13-56-35.png" alt="" width="615" height="491" /></p>
<p>We're almost done, I promise.  In this window select what you want the hotkey to be.  Since I'm coming from a background in Flash, I decided to use F5 to launch the simulator. (Note: You may get a message under "Conflicts" that says F5 is already in use.  Don't worry about that - just hit OK anyways.</p>
<p><img class="alignnone size-full wp-image-1188" title="F5" src="http://producerism.com/wp-content/uploads/2011/05/Enter-Keyboard-Shortcut_2012-04-24_13-58-35.png" alt="" width="320" height="380" /></p>
<p>As mentioned above, if F5 had already been assigned to a shortcut, just overwrite it by clicking <strong>Remove</strong></p>
<p><img class="alignnone size-full wp-image-1189" title="Remove" src="http://producerism.com/wp-content/uploads/2011/05/Warning_2012-04-24_13-57-10.png" alt="" width="582" height="128" /></p>
<p>That's it!  You should now be able to hit F5, and your code will launch instantly in the Simulator!  If it's still not working, make sure you have set your main folder (which contains main.lua) as the source.  You can do that by right-clicking on the project folder and selecting <strong>"Source Root</strong>" under the "<strong>Mark Directory As</strong>" option (it's the last option in the menu) as in the screenshot below.</p>
<p><img class="alignnone size-full wp-image-1190" title="Mark as Root" src="http://producerism.com/wp-content/uploads/2011/05/StoryTouch-D_dropbox-ideasDropboxprojectsStoryTouchStoryTouch-Story_2012-04-24_13-59-55.png" alt="" width="478" height="626" /></p>
<h2>Conclusion</h2>
<p>I took <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-4/">my first stab at Lua</a> when writing a custom <a href="http://dambots.com/dame-editor/">DAME </a>exporter for <a href="http://flashpunk.net/">FlashPunk</a>, and swore that my next stab would be with Corona SDK.  I never expected to have an IDE setup for such a smooth build process - and I really didn't expect to port over an entire flash game in a weekend.  Within 10 hours using Corona (for the first time), I had remade a game that originally took 30+ hours with Actionscript 3.  For that reason alone, I'm in love with this SDK - despite the fairly limited set of features (so far).  During this process I also had lots of help from the following places:</p>
<ul>
<li><a href="http://jonbeebe.net/post/1119939987/corona-sdk-review">Corona SDK Review by Jon Beebe</a></li>
<li><a href="http://blog.anscamobile.com/2011/01/flash-to-corona-porting-guide/">Flash to Corona SDK Porting Guide</a></li>
<li><a href="http://blog.sharifhkhan.com/post/4179161851/develop-with-lua-corona-sdk-and-idea">Develop with Lua, Corona SDK and IDEA by Sharif H. Khan</a></li>
<li><a href="http://johnlindquist.com/2011/08/08/launch-corona-simulator-from-intellij/">Launch Corona Simulator from IntelliJ by John Lindquist</a></li>
</ul>
<h2>How "Free" is Corona SDK?</h2>
<p>Corona SDK is a commercial product, but free to try indefinitely - meaning you can compile to your own devices/simulators for free, but once you want to deploy into the App Store or Android Market, you need to buy a license for Corona.  The annual license is $199 for either Android or iOS, <em><strong>each </strong></em>($349 for both).  In case you are wondering - yes, this means for iOS development you would pay $199 for Corona SDK, in addition to paying the annual license fee to Apple.</p>
<p>Technically, you can use Adobe AIR and the packager to deploy for both platforms - <a href="http://blog.flashvt.com/2011/03/air-2-6-and-ios-using-flashdevelop-and-cs5-on-windows-7/">and even without the packager</a>.  However, the performance is still an issue, and even so - using Corona SDK to develop is still a bit quicker since so many libraries have been bundled in.  It's not nearly as flexible as rolling your own API for box2d, facebook, openfeint, etc. but again it's much quicker when you just want to get right into making the game/app and not messing around with the setup process.</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/how-to-develop-in-corona-sdk-on-windows/feed/</wfw:commentRss>
		<slash:comments>60</slash:comments>
		</item>
		<item>
		<title>Debugging PHP with PHPStorm and Netbeans</title>
		<link>http://producerism.com/blog/debugging-php-with-phpstorm-and-netbeans/</link>
		<comments>http://producerism.com/blog/debugging-php-with-phpstorm-and-netbeans/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 16:23:04 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=792</guid>
		<description><![CDATA[Recently I've gotten back into some fairly intensive PHP coding which required a deeper level of analysis than simple echo statements and standard error messages when debugging. Personally, I use XAMPP for my testing servers, so here is a tutorial for setting up XAMPP and Xdebug for testing. I'll also show the steps for setting [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I've gotten back into some fairly intensive PHP coding which required a deeper level of analysis than simple echo statements and standard error messages when debugging.  Personally, I use XAMPP for my testing servers, so here is a tutorial for setting up XAMPP and Xdebug for testing.  I'll also show the steps for setting up your IDE (either Netbeans or my preference, Jetbrains PHP Storm).<span id="more-792"></span></p>
<h2>Step 1 - Download and Install</h2>
<p>First, download XAMPP 1.7.1, and Netbeans (free) or PhpStorm (30-day trial)</p>
<ol style="list-style: lower-alpha;">
<li>Server: <a href="http://sourceforge.net/projects/xampp/files/XAMPP%20Windows/1.7.1/">XAMPP</a> (it comes with <a href="http://www.xdebug.org/">Xdebug</a>)</li>
<li>PHP IDE: <a href="http://netbeans.org/downloads/index.html">Netbeans </a>(PHP Version) or <a href="http://www.jetbrains.com/phpstorm/">Jetbrains PhpStorm</a></li>
</ol>
<h2>Step 2 - Verify that you have Xdebug</h2>
<ol style="list-style: lower-alpha;">
<li>Look inside of <strong>c:/xampp/php/ext</strong> for a file named <strong>php_xdebug.dll</strong>.  If it's there, move on to step 3.</li>
<li>The file you downloaded from Xdebug looks something like "php_xdebug-x.x.dll."</li>
<li>Rename that to just "php_xdebug.dll."</li>
<li>Copy that file int your <strong>xampp/php/ext</strong> folder (e.g. <strong>c:/xampp/php/ext/php_xdebug.dll</strong>)</li>
</ol>
<h2>Step 3 - Edit php.ini in XAMPP</h2>
<p>Depending on your version of XAMPP (I'm using <strong>1.7.1</strong>l), the <strong>php.ini</strong> file you need to edit will either be in <strong>xamp/apache/bin/php.ini</strong>, or <strong>xamp/php/php.ini</strong>.  <em>If you have a php.ini file in <strong>both </strong>locations, edit the one in apache/bin.</em></p>
<ol style="list-style: lower-alpha;">
<li>Open the php.ini file, and search for "[Zend]."  Comment out anything in that entire column (specifically zend_extension_ts, zend_extension_manager and zend_optimizer)</li>
<li>Now search for "[XDebug]" in the file.  If it doesn't exist, create it yourself.  Then add these lines to it:</li>
</ol>
<pre class="brush: ini">[XDebug]
zend_extension_ts="c:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_enable=true</pre>
<p>You should have a section of your php.ini file that looks something like this:</p>
<pre class="brush:ini">[Zend]
;zend_extension_ts = "c:\xampp\php\zendOptimizer\lib\ZendExtensionManager.dll"
;zend_extension_manager.optimizer_ts = "c:\xampp\php\zendOptimizer\lib\Optimizer"
;zend_optimizer.enable_loader = 0
;zend_optimizer.optimization_level=15
;zend_optimizer.license_path =
; Local Variables:
; tab-width: 4
; End:

[XDebug]
;; Only Zend OR (!) XDebug
zend_extension_ts="c:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_enable=true</pre>
<h2>Step 4 - Restart / Start Apache, and Verify Xdebug</h2>
<p>Now that you have Xdebug installed, restart apache from the XAMPP control panel and verify that Xdebug is configured correctly.  First, Verify PHP is working properly.  Create a php file inside of XAMPP/htdocs (e.g. XAMPP/htdocs/index.php) that just contains:</p>
<pre class="brush:php">&lt;? phpinfo(); ?&gt;</pre>
<p>Now open up http://localhost/index.php in a browser, and you should see something that looks like this:</p>
<p><a href="http://producerism.com/wp-content/uploads/2011/04/phpinfo.png"><img class="alignnone size-full wp-image-794" title="phpinfo" src="http://producerism.com/wp-content/uploads/2011/04/phpinfo.png" alt="" width="510" height="264" /></a></p>
<p>Copy everything on that page (not the source-code, but the actual text on the page), and paste it into the form here: <a href="http://xdebug.org/find-binary.php">http://xdebug.org/find-binary.php</a></p>
<p>If Xdebug is installed correctly, you will see a confirmation page, otherwise you will have some error messages along with suggestions for fixing them.</p>
<p><a href="http://producerism.com/wp-content/uploads/2011/04/xdebug-check.png"><img class="alignnone size-full wp-image-795" title="xdebug-check" src="http://producerism.com/wp-content/uploads/2011/04/xdebug-check.png" alt="" width="510" height="264" /></a></p>
<h2>Step 5 - Setup your PHP IDE for debugging with Xdebug</h2>
<p>Now that you have Xdebug installed and running in apache (via XAMPP) let's setup your IDE.</p>
<h3>Netbeans</h3>
<p><img class="alignnone size-full wp-image-796" title="netbeans691" src="http://producerism.com/wp-content/uploads/2011/04/netbeans691.png" alt="" width="390" height="117" /></p>
<p>As you can notice, I'm using version 6.9.1 instead of the new 7.0, because there are a few features that aren't working yet in 7.0.  I mentioned at the beginning of this post that I actually prefer Jetbrains PhpStorm 2.0.  That being said, I figured I should cover setting up Netbeans, since it's free.</p>
<p>First, just create a new PHP Application Project:</p>
<p><img class="alignnone size-full wp-image-797" title="netbeans-step1" src="http://producerism.com/wp-content/uploads/2011/04/netbeans-step1.png" alt="" width="739" height="167" /></p>
<p>Now, enter a project name ("HelloXdebug") and set the source folder to a subfolder within XAMPP\htdocs (e.g. c:\xampp\htdocs\HelloXdebug). Then click Next.</p>
<p><img class="alignnone size-full wp-image-798" title="netbeans-step2" src="http://producerism.com/wp-content/uploads/2011/04/netbeans-step2.png" alt="" width="739" height="167" /></p>
<p>After clicking Next, you will be on Step 3.  Change "Run As:" to "Script (run in command line).</p>
<p><img class="alignnone size-full wp-image-799" title="netbeans-step3" src="http://producerism.com/wp-content/uploads/2011/04/netbeans-step3.png" alt="" width="739" height="167" /></p>
<p>Then, click on the Configure button next to PHP Interpreter.  This is where we need to set the location of php.exe.</p>
<p><img class="alignnone size-full wp-image-800" title="netbeans-step4" src="http://producerism.com/wp-content/uploads/2011/04/netbeans-step4.png" alt="" width="739" height="167" /></p>
<p>After clicking the Configure button, a new window will pop up.  Just click the Browse button and navigate to XAMPP\php\php.exe</p>
<p><img class="alignnone size-full wp-image-801" title="netbeans-step5" src="http://producerism.com/wp-content/uploads/2011/04/netbeans-step5.png" alt="" width="739" height="167" /></p>
<p>And just below that, are some check boxes for "Stop at First Line" and "Watches and Balloon Information."  Personally, I would just check the latter of the two, and not the first one.  You may get a warning saying that Xdebug can cause problems with Watches/Balloon Evaluation, and you probably will have problems, but they are minor.</p>
<p><a href="http://producerism.com/wp-content/uploads/2011/04/netbeans-step6.png"><img class="alignnone size-full wp-image-802" title="netbeans-step6" src="http://producerism.com/wp-content/uploads/2011/04/netbeans-step6.png" alt="" width="739" height="167" /></a></p>
<p>Now just accept all of your changes, and click <strong>Finish</strong>!</p>
<p>To test out the debugger, here is a very basic example script.</p>
<pre class="brush:php">&lt;?
$fruitBasket = array(
    'apple',
    'pear',
    'orange'
);

foreach($fruitBasket as $fruit)
{
    $currentFruit = $fruit;
    echo $fruit;
}

?&gt;</pre>
<p>We're simply creating an array called $fruitBasket, with a few strings in it.  Then, we iterate through that array, set a temporary variable for each step, and then echo out the fruit name.  This is where we will see the debugger in action.  Just click on the Debug button in the toolbar to see it work.</p>
<p><img class="alignnone size-full wp-image-803" title="netbeans-debugbutton" src="http://producerism.com/wp-content/uploads/2011/04/netbeans-debugbutton.png" alt="" width="739" height="167" /></p>
<h3>Jetbrains PhpStorm</h3>
<p><img class="alignnone size-full wp-image-808" title="phpstorm" src="http://producerism.com/wp-content/uploads/2011/04/phpstorm.png" alt="" width="390" height="117" /></p>
<p>PhpStorm 2.0 is my preferred IDE for working on PHP sites, because there are a few features that are a little more fleshed out, such as subversion (and git) integration, more options for debugging, and some other small comforts.  Anyways, the process is pretty similar when setting PhpStorm up with Xdebug.  First, create a new project.  We'll call it "HelloXdebugStorm."</p>
<p><img class="alignnone size-full wp-image-810" title="phpstorm-step1" src="http://producerism.com/wp-content/uploads/2011/04/phpstorm-step1.png" alt="" width="739" height="167" /></p>
<p>Since it's an empty project, we need to add a PHP file.  Right-click on the project, or go into the File menu and select New &gt; PHP File:</p>
<p><img class="alignnone size-full wp-image-811" title="phpstorm-step2" src="http://producerism.com/wp-content/uploads/2011/04/phpstorm-step2.png" alt="" width="739" height="167" /></p>
<p>A window will ask you for the file name and extension.  We'll be using "index.php" for this tutorial:</p>
<p><img class="alignnone size-full wp-image-812" title="phpstorm-step3" src="http://producerism.com/wp-content/uploads/2011/04/phpstorm-step3.png" alt="" width="739" height="167" /></p>
<p>Still with me?  Now just copy and paste the code from above (in the Netbeans example) into your new index.php file.  For some reason line numbers are disabled by default.  This isn't important to this tutorial, but anyways just right click in the margin of the editor to enable line numbers:</p>
<p><img class="alignnone size-full wp-image-813" title="phpstorm-step4" src="http://producerism.com/wp-content/uploads/2011/04/phpstorm-step4.png" alt="" width="739" height="167" /></p>
<p>Great, let's try debugging (don't get your hopes up, we're going to get an error first).  Right click anywhere in the code, and select "Debug index.php" from the menu:</p>
<p><img class="alignnone size-full wp-image-814" title="phpstorm-step5" src="http://producerism.com/wp-content/uploads/2011/04/phpstorm-step5.png" alt="" width="739" height="167" /></p>
<p>If our debugger was already setup, this would be the final step.  In our case, we're going to get an error message:</p>
<p><img class="alignnone size-full wp-image-815" title="phpstorm-editconfig" src="http://producerism.com/wp-content/uploads/2011/04/phpstorm-editconfig.png" alt="" width="394" height="439" /></p>
<p>As you can see, the error says "PHP home is not specified."  Click the <strong>Fix </strong>button to correct this, and you will see the following window:</p>
<p><img class="alignnone size-full wp-image-816" title="phpstorm-step6" src="http://producerism.com/wp-content/uploads/2011/04/phpstorm-step6.png" alt="" width="739" height="167" /></p>
<p>Notice the warning again, that "PHP home is not specified."  Just click the browse button ("...") and navigate to your php.exe (e.g. c:\xampp\php\php.exe).  As soon as you select php.exe, the warning will change to a confirmation of your PHP version:</p>
<p><img class="alignnone size-full wp-image-817" title="phpstorm-step7" src="http://producerism.com/wp-content/uploads/2011/04/phpstorm-step7.png" alt="" width="739" height="167" /></p>
<p>Now we can debug!  Of course, without any breakpoints nothing special is going to happen.  Set a breakpoint in the code by clicking in the left margin.  You will see a breakpoint (represented by a red circle) wherever you click.  Now when you debug, the code will stop at that point.</p>
<p><img class="alignnone size-full wp-image-818" title="phpstorm-step8" src="http://producerism.com/wp-content/uploads/2011/04/phpstorm-step8.png" alt="" width="739" height="167" /></p>
<p>Either right click in your code and select the "Debug index.php" option as before, or use the debug button on the toolbar:</p>
<p><img class="alignnone size-full wp-image-819" title="phpstorm-step9" src="http://producerism.com/wp-content/uploads/2011/04/phpstorm-step9.png" alt="" width="739" height="167" /></p>
<p>That's it!  You should now be able to debug using either Netbeans or PhpStorm.  Chances are, following this tutorial, you should also be able to setup other IDEs, using other servers as well since all of the steps are pretty much the same.</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/debugging-php-with-phpstorm-and-netbeans/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>FlashPunk, DAME and Lua Tutorial (Part 5)</title>
		<link>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-5/</link>
		<comments>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-5/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 18:18:39 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[FPDameTemplates]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=773</guid>
		<description><![CDATA[After covering various game engines and level editors for flash, the project layout, the DAME templates, the XML format of our levels, and the Lua export script, we're finally ready to get into the ActionScript.  Along with learning Lua in the last step, this was also my first experience using FlashPunk.  As I mentioned in [...]]]></description>
			<content:encoded><![CDATA[<p>After covering various <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-0/">game engines and level editors for flash</a>, the <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-1/">project layout</a>, the <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-2/">DAME templates</a>, the <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-3/">XML format of our levels</a>, and the <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-4/">Lua export script</a>, we're finally ready to get into the ActionScript.  Along with learning Lua in the last step, this was also my first experience using FlashPunk.  As I mentioned in <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-0/">part 0</a>, after experimenting with Flixel and PushButton, FlashPunk just seemed to work closer to the way I design games in my head (and on paper).</p>
<p>The overall structure of the code is pretty simple.  Take a look at the following diagram, which illustrates the components used in the tutorial.</p>
<p><img class="alignnone size-full wp-image-774" title="fpdametemplates-design_overview" src="http://producerism.com/wp-content/uploads/2011/04/fpdametemplates-design_overview.png" alt="" width="650" height="356" /><span id="more-773"></span></p>
<p>As you can see, the main class is <strong>FPDameTemplatesTutorial.as</strong>, which is the class we have set to "Always Compile" in FlashDevelop:</p>
<p><img class="alignnone size-full wp-image-777" title="fpdametemplates-always_compile" src="http://producerism.com/wp-content/uploads/2011/04/fpdametemplates-always_compile.png" alt="" width="390" height="135" /></p>
<p>Let's take a look at the actual code from <strong>FPDameTemplatesTutorial.as:</strong></p>
<p><strong><img class="alignnone size-full wp-image-855" title="level1" src="http://producerism.com/wp-content/uploads/2011/04/level1.png" alt="" width="224" height="195" /><br />
</strong></p>
<pre class="brush: as3; first-line:1;">package
{
	import net.flashpunk.Engine;
	import net.flashpunk.FP;

	/**
	* FlashPunk, DAME and LUA Tutorial
	*
	* @author 	Thomas Gorence
	* @see		http://producerism.com
	*
	* This tutorial was written to be followed along
	* with a series on the producerism.com/blog
	*/

	public class FPDameTemplatesTutorial extends Engine
	{

		public function FPDameTemplatesTutorial():void
		{
			// make sure this matches your compiler settings
			// you can set the numbers to almost anything
			super(800, 500);

			// this will display FPS and other info
			// comment this line to turn it off
			FP.console.enable();
		}

		override public function init():void
		{
			trace("FlashPunk has initialized");
			FP.world = new TestWorld();
			super.init();
		}

	}
}</pre>
<p>Not including any of the imports, class definitions, or comments, there's really only 4 lines of code here that are doing anything.  First of all, we only need to import 2 classes from FlashPunk: the <a href="http://flashpunk.net/docs/net/flashpunk/Engine.html">Engine</a>, and the global helper class, <a href="http://flashpunk.net/docs/net/flashpunk/FP.html">FP</a>.</p>
<pre class="brush: as3; first-line:3;">	import net.flashpunk.Engine;
	import net.flashpunk.FP;</pre>
<p><strong>Engine </strong>is just a very specialized MovieClip, which handles lots of game-related functions like maintaining the frame rate, reacting to items being added to the stage, and basically anything time-related.  For the most part, you won't ever need to set your own Timers or ENTER_FRAME listeners.  All of that happens within this Engine class (automatically).</p>
<p><strong>FP</strong> is a class with all static functions (meaning you can access them without creating an "FP" object).  It's your go-to class for getting and setting global information like the camera, frame rate and screen size, along with lots of utility functions for checking collisions, sorting objects, loading, etc.</p>
<p>The constructor function within our main class (FPDameTemplatesTutorial.as) does two things:</p>
<pre class="brush:as3; first-line:19">		public function FPDameTemplatesTutorial():void
		{
			// make sure this matches your compiler settings
			// you can set the numbers to almost anything
			super(800, 500);

			// this will display FPS and other info
			// comment this line to turn it off
			FP.console.enable();
		}</pre>
<p>On line 23, we use super() to call the constructor function of the class we've extended (net.flashpunk.Engine).  Here's a peak at what Engine is looking for <strong>(Engine.as):</strong></p>
<pre class="brush:as3; first-line:50">public function Engine(width:uint, height:uint, frameRate:Number = 60, fixed:Boolean = false)</pre>
<p>Since it's looking for width, height, frameRate and fixed (whether or not to set a fixed frame rate), we need to pass in at least the width and the height.  So that's exactly what we do on line 23.  Then on line 27, we enable the FlashPunk debugging console, which is extremely helpful in development.</p>
<p>After the constructor function has run, and once FlashPunk has initialized, it will fire the <strong>init()</strong> function in our <strong>FPDameTemplatesTutorial.as:</strong></p>
<pre class="brush:as3; first-line:30">		override public function init():void
		{
			trace("FlashPunk has initialized");
			FP.world = new TestWorld();
			super.init();
		}</pre>
<p>This is an override function, meaning that it's already part of the Engine class we extended, so it's being called on it's own.  However, if we want to add some custom functions we need to write our own <strong>init()</strong> before letting the <strong>Engine </strong>run it's own code, called on <strong>line 34</strong> with <strong>super.init()</strong>.  On <strong>line 33</strong>, we set the global <strong>world </strong>variable by using the FP helper class.  By setting the world, we are telling FlashPunk to load our <strong>TestWorld()</strong> class.  <strong>FP.world</strong> is basically the current screen/state/level.  For example, splash screens, menu screens, different levels, top score screens, these are all "worlds" in FlashPunk terms.  I believe in Flixel they are called <a href="http://flixel.org/docs/org/flixel/FlxState.html">states</a>.  Then, when we call <strong>super.init()</strong>, our game actually starts.</p>
<h2>TestWorld</h2>
<p><strong><img title="level2" src="http://producerism.com/wp-content/uploads/2011/04/level2.png" alt="" width="224" height="195" /></strong></p>
<p>The only custom class we referenced in the main class above was <strong>TestWorld.as:</strong></p>
<pre class="brush:as3; first-line:17">public class TestWorld extends World
	{

		// since the maps in DAME can be of different widths, we need
		// a way to keep track of the total length of the level we generate
		private var _totalMapsWidth:Number = 0.0;

		// create a variable for the player, to use in the update() function
		private var _player:Entity;

		public function TestWorld()
		{
			trace("TestWorld Constructor");
			super();
		}</pre>
<p>This is essentially the code which drives the entire game, by adding the background, player, and level items (tiles and enemies) which we created in DAME.  To keep things simple, we've only created two private variables for this World on <strong>lines 22 and 25</strong>.<br />
<strong>_totalMapsWidth </strong>is just a number to keep track of the entire length of the level generated.  Remember that this project will create an infinitely long level, and to make use of the FlashPunk camera system, we need to keep track of the total offset.  The other variable, <strong>_player</strong>, is self-explanatory; it just holds a reference to the player's character, so it can be referenced in the <strong>update()</strong> function.</p>
<p>Just like the override init() function from the FPDameTemplatesTutorial class (which extended the FlashPunk Engine class), our TestWorld() extends the World class.  In this case we want to override two functions, begin() and update().  Let's look at <strong>begin():</strong></p>
<pre class="brush:as3;first-line:33;">		override public function begin():void
		{

			// add the background first, so that it's on the bottom be default
			add(new BackgroundEntity);

			// add the player, and set depth to make sure they are always on top
			_player = add(new Zeppelin);
			_player.layer = -1;

			// generate maps until they fill the entire screen
			while (_totalMapsWidth &lt; FP.stage.width + FP.camera.x)
			{
				spawnMap();
			}

			super.begin();
		}</pre>
<p>As you can guess, the begin() function runs when our <strong>World </strong>has been set to be the active <strong>FP.world</strong>.  On <strong>line 37</strong>, we add our <strong>BackgroundEntity </strong>(this is the scrolling background image for a parallax effect).  Then on <strong>line 40</strong>, we create our <strong>_player</strong>, using a <strong>Zeppelin </strong>class, and set the layer to -1, which makes sure it will always be on top (the lower the number, the higher the entity will be in the depth-sorting).<br />
On <strong>lines 44-47</strong>, we just have a loop that will create maps until the screen is totally full.  As you can see, we're checking whether our <strong>_totalMapsWidth </strong>is smaller than the with of the stage plus the x position of our camera - and if it's smaller, we just spawn another map and check again.</p>
<p>The <strong>update()</strong> function is pretty similar:</p>
<pre class="brush:as3;first-line:52;">		override public function update():void
		{
			// just have the camera follow the player
			FP.camera.x = _player.x - 50;

			// generate maps until they fill the entire screen
			while (_totalMapsWidth &lt; FP.stage.width + FP.camera.x)
			{
				spawnMap();
			}

			super.update();
		}</pre>
<p>On line 55, we simply make sure the camera is always 50 pixels behind our _player.  This means we really only have to move our player around in code, and the camera will make sure everything else (backgrounds, objects, enemies, maps) pass by automatically.  As before we simply call <strong>spawnMap()</strong> to generate a new map (based on the DAME templates) until the screen is full (<strong>lines 58-61</strong>).</p>
<p>We've already added the background and the <strong>_player </strong>to our screen, so lets look at the last function, <strong>spawnMap()</strong>, which takes care of everything else:</p>
<pre class="brush:as3;first-line:66;">		private function spawnMap():void
		{
			// generate a random number, based on the total map layers in XML exported from DAME
			var randomMapNumber:Number = Math.ceil(Math.random() * Assets.LEVEL_TEMPLATES_COUNT);
			var mapLayer:String = "template" + randomMapNumber;

			// notice we are using add() and not create(), which is why we're also setting recycleMaps to false
			var testMap:TilemapGeneratorEntity = new TilemapGeneratorEntity(Assets.LEVEL_TEMPLATES_XML, Assets.BG_TILES, mapLayer, "level", _totalMapsWidth, 0, true, false);
			add(testMap);

			// update the total length of the generated level so far, so we know where to place the next map
			_totalMapsWidth += testMap.mapLayerWidth;
		}</pre>
<p>First, we grab a random number between 1 and the total number of maps (<strong>&lt;tiles&gt;</strong> nodes) in our exported XML file (<strong>line 69</strong>).  I've actually stored the number of maps in a constant variable called <strong>Assets.LEVEL_TEMPLATES_COUNT</strong>, which I'll go into later.  Then we just create a string for the name of the random template (e.g. "template4" will refer to "template4" in our DAME project).  Next, we generate the tilemap using a custom class, <strong>TilemapGeneratorEntity </strong>(<strong>line 73</strong>) and then add it to the world (<strong>line 74</strong>).  Finally, we update the <strong>_totalMapsWidth</strong>, to keep track of how wide our world is after adding the newly generated map.</p>
<h2>BackgroundEntity</h2>
<p><img class="alignnone size-full wp-image-857" title="level3a" src="http://producerism.com/wp-content/uploads/2011/04/level3a.png" alt="" width="224" height="195" /></p>
<p>Within our TestWorld class that we just covered, we really only added three entities (any object added to a World in FlashPunk is called an Entity).  The first of those entities was called <strong>BackgroundEntity.as</strong>.  Since all of the code within this class is in the constructor function, let's just look at that:</p>
<pre class="brush:as3;first-line:22;">		public function BackgroundEntity()
		{
			// create tilemap
			var _tiles:Tilemap = new Tilemap(Assets.BG_TILES, 32, 32, 32, 32);
			_tiles.setTile(0, 0, 7);

			// crate bitmapdata from tilemap
			var _bitmapData:BitmapData = new BitmapData(_tiles.width, _tiles.height, true, 0x00ffffff);
			_tiles.render(_bitmapData, new Point(0, 0), FP.camera.clone());

			// create a backdrop from bitmapdata (seamless tile background)
			var _backdrop:Backdrop = new Backdrop(_bitmapData);
			_backdrop.scrollX = _backdrop.scrollY = .5;

			// set the graphic to the backdrop
			graphic = _backdrop;
		}</pre>
<p>First, we create a FlashPunk Tilemap, which is a class that acts as a canvas to quickly draw tiles on.  When creating the Tilemap, we pass in the actual tile images (bgtiles.png), followed by the width/height of the entire tilemap, followed by the width/height of each tile.  In this tutorial, our tilemap is the same size as one tile (32px by 32px), because we will just repeat that single tile as the background.  If we wanted a more detailed background, we could create a much bigger tilemap.  Then, since our bgtiles.png file actually has 10 32x32 pixels in it, we want to select the 8th tile (index of 7, since all arrays start at 0!) on <strong>line 26</strong>.</p>
<p><img class="alignnone size-full wp-image-781" title="fpdametemplates-bgtiles" src="http://producerism.com/wp-content/uploads/2011/04/fpdametemplates-bgtiles.png" alt="" width="640" height="64" /></p>
<p>Now that we've created a Tilemap (which is really just a single tile right now), we want to repeat that map (again, just a single tile for this tutorial) seamlessly, and add a parallax scrolling effect to it.  Luckily, there is a <strong>Backdrop</strong> class included with FlashPunk which serves this exact purpose.  Since it requires a <strong>BitmapData</strong> instead of a Tilemap, we create the bitmap data on lines <strong>29-30</strong>.  We simply create a BitmapData object that is 32px by 32px, then use the <strong>_tiles.render()</strong> function (inherited from <strong>FP.graphics.Canvas</strong>) to draw the tilemap into <strong>_bitmapData</strong>.</p>
<p>That may seem like a convoluted way to create a <strong>Backdrop</strong> from a <strong>Tilemap</strong> in FlashPunk - and it probably is.  However, I couldn't find a better way to do this, even with help from the <a href="http://flashpunk.net/forums/index.php?topic=109.0">FlashPunk IRC channel</a>, <a href="http://flashpunk.net/forums/index.php">forum</a> and other tutorials.  If you know of a better way, please let me know!  Anyways, now that we have a <strong>_bitmapData</strong>, we can finally pass that into a very anti-climactic Backdrop object on <strong>line 33</strong>.  Then, to add the nifty scrolling effect we simply set the _backdrop.scrollX and scrollY to 0.5, which means the background will scroll at half the rate of our camera (e.g. if our map scrolls 10px, our background will only scroll 5px).</p>
<p><img class="alignnone size-full wp-image-782" title="fpdametemplates-backdrop" src="http://producerism.com/wp-content/uploads/2011/04/fpdametemplates-backdrop.png" alt="" width="400" height="200" /></p>
<p>Finally, we set the graphic of our Entity (BackgroundEntity) to the <strong>_backdrop</strong> that we went through all this trouble creating.  Now when it's added to the TestWorld, it will simply show up on the screen, and will automatically scroll with the parallax effect when the camera moves.</p>
<h2>Zeppelin</h2>
<p><img class="alignnone size-full wp-image-858" title="level3b" src="http://producerism.com/wp-content/uploads/2011/04/level3b.png" alt="" width="224" height="195" /></p>
<p>Still with me?  Good.  Let's take a look at our <strong>_player</strong>, which uses the <strong>Zeppelin</strong> class.  Again to make it easier to follow along, we'll just look at the main functions and ignore all of the imports.<br />
We only have two private variables for this class:</p>
<pre class="brush:as3;first-line:23">		// setting an upward force to pull Zeppelin up
		private static const GRAVITY:Number = -35.0;

		// how fast Zeppelin moves up/down and forward
		private var _speed:Number = 200.0;</pre>
<p>Unlike most games, we've set our GRAVITY to be negative in this tutorial.  The reason is because our Zeppelin will always be rising up into the air (at a rate of -35 pixels), and the player will need to push the Zeppelin back down.  We also set the _speed of our Zeppelin, which is how fast it moves up and down when the player uses the arrow keys to control it.</p>
<p>Our Zeppelin constructor function is pretty simple:</p>
<pre class="brush:as3;first-line:29;">		public function Zeppelin()
		{
			x = 20;
			y = 50;
			mask = new Pixelmask(Assets.ZEPPELIN_SPRITE);
			graphic = new Image(Assets.ZEPPELIN_SPRITE);
			type = "player";
		}</pre>
<p>The x and y coordinates are set so that the Zeppelin is at the top left of the screen when we start.  Then, we create a mask for pixel-perfect collisions using the <strong>Pixelmask</strong> class (another awesome feature of FlashPunk).  With the mask set, we just assign the same image we used for the mask, to the graphic of the Zeppelin Entity (remember, when dealing with FlashPunk Entities, the "<strong>graphic</strong>" is what gets drawn to the screen).</p>
<p>The only remaining function in this Zeppelin class is what makes the Zeppelin move, <strong>update():</strong></p>
<pre class="brush:as3;first-line:38;">override public function update():void
		{

			var xPos:Number = x;
			var yPos:Number = y;

			// apply gravity
			yPos += GRAVITY * FP.elapsed;</pre>
<p>Right away, we store the current position of our Zeppelin into <strong>xPos</strong> and <strong>yPos</strong>.  Remember, this is an <strong>override function</strong> (<strong>line 38</strong>), so FlashPunk is calling this (<strong>Zeppelin.update()</strong>) for us every frame, while the game is game is running.  We want to move our Zeppelin in sync with the camera and other entities, so we multiply any offsets by <strong>FP.elapsed</strong>.  This was hard to grasp at first, but easy to think of it this way: The default FPS for the FlashPunk <strong>Engine</strong> class is 60, so instead of GRAVITY pushing our Zeppelin up by -35px each second, we're actually pushing our Zeppelin up by GRAVITY/FPS (-35/60), each time the update() function gets called.</p>
<p>With that out of the way, lets look at the rest of our Zeppelin:</p>
<pre class="brush:as3;first-line:47;">// forward movement
			xPos += _speed * FP.elapsed;

			// Input checking
			if (Input.check(Key.UP))
			{
				// move up
				yPos -= _speed * FP.elapsed;
			} else if (Input.check(Key.DOWN))
			{
				// move down
				yPos += _speed * FP.elapsed;
			}

			// finally, set the Zeppelin's position (within limits!)
			y = Math.min(FP.stage.height-height,Math.max(0,yPos));
			x = xPos;

			super.update();
		}</pre>
<p>Notice that our Zeppelin already has an inherent speed, so the first thing we to to the x position (<strong>xPos</strong>), is apply that forward speed.  Next, we use the <strong>Input</strong> helper class to check for button presses.  Then, before calling <strong>super.update()</strong>, we set the position of the actual Zeppelin.  I'm using <strong>Math.min()</strong> and <strong>Math.max()</strong> (<strong>line 62</strong>) to ensure the Zeppelin never goes off the screen on the <strong>y</strong> axis, but there are lots of other ways to do this.</p>
<p>We've covered the main <strong>Engine</strong> class of FlashPunk (<strong>FPDameTemplatesTutorial.as</strong>), the <strong>World</strong> class (<strong>TestWorld.as</strong>), the <strong>BackgroundEntity.as</strong>, which is our scrolling background with the parallax effect, and even our <strong>Zeppelin</strong> class (<strong>Entity</strong>), which the player controls.</p>
<p>Of course, so far none of this code has touched on where our DAME templates come into the picture, which is all handled in the <strong>TilemapGeneratorEntity.as</strong> class.  It's a good time to take a break, so that's the first thing we'll cover in the next part to this tutorial series.</p>
<p><a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-6">Continue to Part 6</a></p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FlashPunk, DAME and Lua Tutorial (Part 4)</title>
		<link>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-4/</link>
		<comments>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-4/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 18:02:37 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[FPDameTemplates]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=744</guid>
		<description><![CDATA[In the fourth part of this tutorial, I'll finally get into the Lua code.  Since this was my first experience with Lua so far, I'll also include some thoughts and other tutorials I discovered in the process.  Here are links for the previous parts in the tutorial, 0, 1, 2 and 3.  As always, if [...]]]></description>
			<content:encoded><![CDATA[<p>In the fourth part of this tutorial, I'll finally get into the Lua code.  Since this was my first experience with Lua so far, I'll also include some thoughts and other tutorials I discovered in the process.  Here are links for the previous parts in the tutorial, <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-0/">0</a>, <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-1/">1</a>, <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-2/">2</a> and <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-3">3</a>.  As always, if you haven't already downloaded the project files, grab them <a href="http://producerism.com/wp-content/uploads/2011/01/FPDameTemplatesTutorial.zip">here</a>.</p>
<p>Since I'm still brand new to Lua, I won't go into the language itself, since the syntax is very similar to ActionScript.  What is important to read over though, are the <a href="http://damehelp.dambots.com/index.php/Writing_An_Exporter">DAME functions</a> to make use of within the Lua scripts.  These custom functions are what makes everything happen, and I spent a few hours reading over the complete list of them in creating this exporter.</p>
<p>First of all, you will need to copy both of the Lua files in this project (<strong>FPDameTemplatesTutorial.lua</strong> and <strong>FPDameTemplatesTutorial_settings.lua</strong>) into the <strong>lua/Exporters</strong> folder within the <strong>DAME installation directory</strong> (mine was C:\Program Files\DAME\lua\Exporters).</p>
<p>The settings file (<strong>FPDameTemplatesTutorial_settings.lua</strong>) is only used for displaying a description and additional options within the DAME export window. For a reference, this is what the export window will look like when using the FPDameTemplatesTutorial_settings.lua file:</p>
<p><a href="http://producerism.com/wp-content/uploads/2011/04/dame-export-window.jpg"><img class="alignnone size-full wp-image-745" title="dame-export-window" src="http://producerism.com/wp-content/uploads/2011/04/dame-export-window.jpg" alt="" width="536" height="407" /><span id="more-744"></span></a></p>
<p>Here is the code for <strong>FPDameTemplatesTutorial_settings.lua:</strong></p>
<pre class="brush: lua;">-- Display the settings for the exporter.
DAME.AddHtmlTextLabel("An XML exporter made by T (producerism.com) for the FPDameTemplatesTutorial... tutorial.")
DAME.AddTextInput("Relative Export Path", "", "RelativeExportPath", true, "The path (relative to the .dam project file) to export the xml." )
DAME.AddTextInput("Level Name", "", "LevelName", true, "The name you wish to call this level." )
return 1</pre>
<p>You can see that only 3 of those lines are doing anything interesting, specifically the last two.  These are DAME functions which add additional controls to the export window.  The two fields I've added are both TextInputs.  From the second parameter you can see the names of these fields are "<strong>RelativeExportPath</strong>" and "<strong>LevelName</strong>."  Those will be made available to the main script which actually parses the tile/sprite/map information and exports a map (in our case, XML).</p>
<p>Here is the code for <strong>FPDameTemplatesTutorial.lua</strong>.  I decided not to show it all at once, since it will be easier to explain step by step.</p>
<p><strong>Lines 1-23</strong> define a function for initializing the exporter:</p>
<pre class="brush: lua;">function init()
	-- Sets the number of decimal places to be displayed after any floating-point numbers in your output text
	DAME.SetFloatPrecision(0)

	-- Setup tab strings for convenience
	tab1 = "\t"
	tab2 = "\t\t"
	tab3 = "\t\t\t"
	tab4 = "\t\t\t\t"

	-- This is the string where we will store all of the text to be exported as XML
	fileText = '&lt;level&gt;\n'

	-- create empty arrays for map, sprite, and shape layers
	mapLayers = {}
	spriteLayers = {}
	shapeLayers = {}

	-- generate a default properties string
	propertiesString = "%%proploop%% %propname%=\"%propvalue%\"%%proploopend%%"
end</pre>
<p>First, we set the number of decimal places to be exported (in our case, 0) using DAME.SetFloatPrecision(0).  The tab1-4 variables defined just below that make the exported XML file easier to read within a text editor.  The <strong>fileText</strong> variable is a string which will store all of the text to be exported as an XML file.  Finally, the <strong>propertiesString</strong> is a specially formatted string which DAME will use to find all of the custom properties of any object within the DAME editor.  A full explanation of these properties is explained <a href="http://damehelp.dambots.com/index.php/Writing_An_Exporter#Properties">here</a>.</p>
<p>Now lets look at the <strong>parseLayers()</strong> function on <strong>lines 23-64</strong>, which accounts for most of the code in this file.</p>
<pre class="brush: lua; first-line:23;">-- parse all of the layers in the DAME project, and sort them into the arrays for mapLayers, spriteLayers and shapeLayers
function parseLayers()
	local groups = DAME.GetGroups()
	local groupCount = as3.tolua(groups.length)-1
	-- parse through the groups
	for groupIndex = 0,groupCount do
		local group = groups[groupIndex]
		local groupName = string.gsub(as3.tolua(group.name), " ", "_")
		local layerCount = as3.tolua(group.children.length) - 1

		-- Go through each layer and store some tables for the different layer types.
		for layerIndex = 0,layerCount do
			local layer = group.children[layerIndex]
			local isMapLayer = as3.tolua(layer.map)~=nil
			local isSpriteLayer = as3.tolua(layer.IsSpriteLayer())
			local isShapeLayer = as3.tolua(layer.IsShapeLayer())
			local layerName = string.gsub(as3.tolua(layer.name), " ", "_")

			if isMapLayer then
				table.insert(
					mapLayers,
					{
						layer=layer,
						layerName=layerName,
						xOffset=as3.tolua(layer.map.x),
						yOffset=as3.tolua(layer.map.y),
						mapWidth=as3.tolua(layer.map.width),
						mapHeight=as3.tolua(layer.map.height),
						tileWidth=as3.tolua(layer.map.tileWidth),
						tileHeight=as3.tolua(layer.map.tileHeight),
						mapWidthInTiles=as3.tolua(layer.map.widthInTiles),
						mapHeightInTiles=as3.tolua(layer.map.heightInTiles)
					}
				)
			elseif isSpriteLayer then
				table.insert(spriteLayers,{groupName,layer,layerName})
			elseif isShapeLayer then
				table.insert(shapeLayers, {groupName,layer,layerName})
			end
		end
	end
end</pre>
<p>In this function, we first create a variable to store all of the group layers within our DAME project, using the <a href="http://damehelp.dambots.com/index.php/Writing_An_Exporter#Functions">DAME.GetGroups()</a> function.  Remember, we created 3 groups in our project, <strong>maps</strong>, <strong>sprites</strong> and <strong>shapes</strong>.  Next, we create a variable, <strong>groupCount</strong>, to store the total number of groups (which will be 3 in our case).  On line 28, we begin looping through all of our groups.  To make things easier to read, I've created a variable called <strong>group</strong> to store the current group layer to analyze, <strong>groupName</strong> to store the name of the group (e.g. "maps") and <strong>layerCount</strong> for the total number of layers within a group (e.g. there are 6 layers in the "maps" group).</p>
<p>While we are looping through all of the groups, on <strong>line 34</strong> we loop through the layers within each group.  <strong>Lines 36-38</strong> are simply checking to see what type of layer we're currently parsing, and based on the type, we either go to line <strong>41</strong>, <strong>57</strong>, or <strong>59</strong>.</p>
<p>If the current layer being parsed is a map layer, it's put into the <strong>mapLayers</strong> array (using table.insert), along with an object which contains all of the properties of that map (<strong>lines 44-55</strong>).  If the current layer is a sprite or a shape instead, it's dealt with accordingly.</p>
<p>Now we can cover the only other large function to worry about, <strong>createTileMaps()</strong>.  Although it spans over 30 lines of code (lines 66-103), it's all very simple.</p>
<pre class="brush: lua; first-line:66;">function createTilemaps()

	-- First, format the string we want to create, using $variableName for interpolation
	local mapTextFormat = tab1 .. '&lt;tiles layer="$layerName" x="$xOffset" y="$yOffset" width="$mapWidth" height="$mapHeight" tileWidth="$tileWidth" tileHeight="$tileHeight" widthInTiles="$mapWidthInTiles" heightInTiles="$mapHeightInTiles"&gt;\n'

	local mapText = ''

	for i in ipairs(mapLayers) do
		local map = mapLayers[i]

		-- Second, interpolate $variableName with actual values
		mapText =
			string_interpolate(
				mapTextFormat,
				{
					layerName=map.layerName,
					xOffset=map.xOffset,
					yOffset=map.yOffset,
					mapWidth=map.mapWidth,
					mapHeight=map.mapHeight,
					tileWidth=map.tileWidth,
					tileHeight=map.tileHeight,
					mapWidthInTiles=map.mapWidthInTiles,
					mapHeightInTiles=map.mapHeightInTiles
				}
			)
			..
			-- Parse through all of the subchildren
			as3.tolua(DAME.ConvertMapToText(map.layer,"","",tab2.."&lt;tile","",""," tx=\"%tilex%\" ty=\"%tiley%\" x=\"%pxpos%\" y=\"%pypos%\"/&gt;\n", true))
			..
			tab1
			-- Close the &lt;tiles&gt; tag
			.."&lt;/tiles&gt;\n"

			fileText = fileText .. mapText
	end

end</pre>
<p>Unfortunately, <a href="http://lua-users.org/wiki/StringInterpolation">string interpolation within Lua</a> isn't as nice as some other languages (like PHP or Perl).  You can't just throw variables right into a string (e.g. "Hello $firstname $lastname!" outputs "Hello John Doe!") without writing a helper function.  Or rather, without finding a decent string interpolation function online, like <a href="http://snippets.luacode.org/snippets/String_Interpolation_110">this one</a> (visit the link for an example).  After adding this function, we can put variables right into our string, which makes reading the much easier, as you can see on <strong>line 69</strong>.</p>
<p>After we've defined our string format (<strong>mapTextFormat</strong>), we just pass that string along with an object that contains all of the parameters to interpolate (<strong>lines 80-90</strong>).  The dots you see on <strong>lines 92, 95, and 98</strong> just concatenate all of this text together (into the <strong>mapText</strong> variable).  It should all look fairly straightforward, with the exception of <strong>line 94</strong>, which calls <strong>DAME.ConvertMapToText()</strong>.</p>
<pre class="brush: lua; first-line:93;">			-- Parse through all of the subchildren
			as3.tolua(DAME.ConvertMapToText(map.layer,"","",tab2.."&lt;tile","",""," tx=\"%tilex%\" ty=\"%tiley%\" x=\"%pxpos%\" y=\"%pypos%\"/&gt;\n", true))</pre>
<p>When looking at the <a href="http://damehelp.dambots.com/index.php/Writing_An_Exporter#Functions">DAME Functions list</a>, you can see that the DAME.ConvertMapToText() function accepts parameters for mapLayer, rowPrefix, rowSuffix, columnPrefix, columnSeperator, columnSuffix, keywords, and whether or not to ignoreHiddenTiles.  For this tutorial, we've omitted rowPrefix and rowSuffix, and set "&lt;tile" to be the columnPrefix.  The keywords are defined in the <a href="http://damehelp.dambots.com/index.php/Writing_An_Exporter#Tilemap_keywords">DAME Tilemap Keywords list</a>.</p>
<p>After parsing all of the child ("<strong>&lt;tile&gt;</strong>") nodes, we simple close the parent ("<strong>&lt;tiles&gt;</strong>") tag, then continue on with the loop.  Once all of the tilemaps have been looped through, we append the generated text (<strong>mapText</strong>) to our <strong>fileText</strong> variable.</p>
<p>It's all smooth sailing from here, seriously!  Lets take a look at the <strong>createSprites()</strong> function on <strong>lines 105-112</strong>:</p>
<pre class="brush: lua; first-line:105;">function createSprites()
	for i in ipairs(spriteLayers) do
		fileText = fileText..tab1.."&lt;sprites layer=\""..as3.tolua(spriteLayers[i][2].name).."\"&gt;\n"
		local creationText = tab2.."&lt;sprite className=\"%class%\" x=\"%xpos%\" y=\"%ypos%\" width=\"%width%\" height=\"%height%\""..propertiesString.." /&gt;\n"
		fileText = fileText..as3.tolua(DAME.CreateTextForSprites(spriteLayers[i][2],creationText,"sprite type=\"%spritename%\""))
		fileText = fileText..tab1.."&lt;/sprites&gt;\n"
	end
end</pre>
<p>For the createSprites() function, we just loop through all of the items in the spriteLayers array.  Similar to the <a href="http://damehelp.dambots.com/index.php/Writing_An_Exporter#Functions">DAME.ConvertMapToText()</a> function, we have a <a href="http://damehelp.dambots.com/index.php/Writing_An_Exporter#Functions">DAME.CreateTextForSprites()</a> function which parses all of the sprites in a layer.  Also, just as with DAME.ConvertMapToText(), this function allows us to pass in some <a href="http://damehelp.dambots.com/index.php/Writing_An_Exporter#Common_keywords">DAME Keywords</a>.  The inclusion of <strong>propertiesString</strong> (<strong>line 108</strong>) makes sure that if any custom parameters had been set in DAME, we capture those too.</p>
<p>Almost identical to the <strong>createSprites()</strong> function, is the next function, <strong>createShapes()</strong> on <strong>lines 114-122</strong>.  The only big difference between the functions for sprites and shapes, is that <strong>DAME.CreateTextForShapes()</strong> allows us to pass in a different string format for circles vs rectangles:</p>
<pre class="brush: lua; first-line:114;">function createShapes()
	for i in ipairs(shapeLayers) do
		fileText = fileText..tab1.."&lt;shapes layer=\""..as3.tolua(shapeLayers[i][2].name).."\"&gt;\n"
		local circleText = tab2.."&lt;shape type=\"circle\" x=\"%xpos%\" y=\"%ypos%\" radius=\"%radius%\""..propertiesString.." guid=\"%guid%\" /&gt;\n"
		local rectangleText = tab2.."&lt;shape type=\"rectangle\" x=\"%xpos%\" y=\"%ypos%\" width=\"%width%\" height=\"%height%\""..propertiesString.." guid=\"%guid%\" /&gt;\n"
		fileText = fileText..as3.tolua(DAME.CreateTextForShapes(shapeLayers[i][2],circleText,rectangleText,"shape"))
		fileText = fileText..tab1.."&lt;/shapes&gt;\n"
	end
end</pre>
<p>Almost done... let's just look at the <strong>finish()</strong> function on <strong>lines 124-131</strong>.</p>
<pre class="brush: lua; first-line:124;">function finish()
	-- Get settings from the *_settings.lua file which accopanies this one.
	local levelName = as3.tolua(VALUE_LevelName)
	local relativeExportPath = as3.tolua(DAME.GetProjectFileLocation())..'\\'..as3.tolua(VALUE_RelativeExportPath)..'\\'

	fileText = fileText.."&lt;/level&gt;"
	DAME.WriteFile(relativeExportPath..levelName..".xml", fileText )
end</pre>
<p>The first two lines (126-127) to notice, are where we capture the data from the custom fields defined in the settings.lua file.  As you can see, we simply use the function <strong>as3.tolua()</strong> in order to get the data, while passing in "<strong>VALUE_</strong>" and then the defined name.  If you refer to the settings code above, you can see that since the TextInput name was "<span style="text-decoration: underline;"><strong>LevelName</strong></span>," we are retrieving that data by using <strong>as3.tolua(VALUE_<span style="text-decoration: underline;">LevelName</span>)</strong>.</p>
<p>At this point, we are pretty much done.  All of the tilemaps, sprites, and shapes have been exported to the XML string (still stored in <strong>fileText</strong>).  The very last step is to add our closing &lt;/level&gt; tag, and then write the file using <a href="http://damehelp.dambots.com/index.php/Writing_An_Exporter#Functions">DAME.WriteFile()</a>.</p>
<p>Now that we've covered all of the functions, we simply need to run them all in order.  There are better ways to do this, but to make the file easy to follow along with, I've just called them out one after the other (lines 137-142).</p>
<pre class="brush: lua; first-line:124;">init()
parseLayers()
createTilemaps()
createSprites()
createShapes()
finish()</pre>
<h2>Notes</h2>
<p>As mentioned at the beginning of this post, most of the magic being used is actually via a set of <a href="http://damehelp.dambots.com/index.php/Writing_An_Exporter">functions provided by DAME</a>, which can be referenced <a href="http://damehelp.dambots.com/index.php/Writing_An_Exporter">here</a>.  I want to emphasize that this tutorial is only using a very small number of features available with DAME.  For example, I'm not using any paths, linking, sprite rotation or a few others.  The author of DAME is very responsive, and was a huge help in the process of writing this tutorial.  I found a few bugs/missing features which were fixed/implemented very quickly (within days of notifying the author via email).  In addition to the help I got via email, this <a href="http://jessewarden.com/2011/01/lua-for-actionscript-developers.html">crash course on Lua for ActionScript developers</a> article by Jesse Warden was extremely helpful.</p>
<p>Since originally writing this exporter script (a few months ago), Lua has actually popped up quite a few times in the context of games.  Specifically, the Corona SDK for making mobile games uses Lua, and is another great example of another reason to learn it!  If I decide to cover more Lua in future tutorials, it will probably be via Coronoa.</p>
<p>Anyways, in the next part of <em>this </em>tutorial, we will finally get into the ActionScript which ties all of this together.</p>
<p><a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-5">Continue to Part 5</a></p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FlashPunk, DAME and Lua Tutorial (Part 3)</title>
		<link>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-3/</link>
		<comments>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-3/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 04:13:32 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[FPDameTemplates]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=715</guid>
		<description><![CDATA[Since I've already covered some of the various game frameworks for Flash, decided on a project to make, and explained all of the components within the project - I think it's finally time to get into some code.  If you haven't already downloaded the project files, grab them here. First, take a look at the [...]]]></description>
			<content:encoded><![CDATA[<p>Since I've already covered some of the <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-0/">various game frameworks for Flash</a>, <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-1/">decided on a project</a> to make, and <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-2/">explained all of the components</a> within the project - I think it's finally time to get into some code.  If you haven't already downloaded the project files, grab them <a href="http://producerism.com/wp-content/uploads/2011/01/FPDameTemplatesTutorial.zip">here</a>.</p>
<p>First, take a look at the XML structure we'll be using:</p>
<pre class="brush: xml;">&lt;level&gt;
	&lt;tiles layer="template4" x="1440" y="0" width="480" height="480" tileWidth="32" tileHeight="32" widthInTiles="15" heightInTiles="15" &gt;
		&lt;tile tx="96" ty="0" x="0" y="0"/&gt;
	&lt;/tiles&gt;
	&lt;sprites layer="template4"&gt;
		&lt;sprite className="Balloon" x="1484" y="349" width="35" height="45" points="1" /&gt;
		&lt;sprite className="Balloon" x="1621" y="2" width="35" height="45" points="1" spawnShape="74A916C5-C96B-62BE-6540-024B6D1237CB" spawnAmount="2" color="0x00ff00" /&gt;
		&lt;sprite className="Balloon" x="1818" y="73" width="35" height="45" points="1" /&gt;
		&lt;sprite className="Balloon" x="1750" y="343" width="35" height="45" points="1" spawnShape="74A916C5-C96B-62BE-6540-024B6D1237CB" spawnAmount="5" /&gt;
		&lt;sprite className="FlyingPig" x="1843" y="1" width="60" height="51" spawnShape="5E3E76E3-431E-E1E1-B26C-930B32DB8AB1" spawnAmount="5" /&gt;
		&lt;sprite className="Balloon" x="1629" y="346" width="35" height="45" points="1" /&gt;
	&lt;/sprites&gt;
	&lt;shapes layer="template1"&gt;
		&lt;shape type="rectangle" x="1663" y="286" width="191" height="159" guid="74A916C5-C96B-62BE-6540-024B6D1237CB" /&gt;
		&lt;shape type="rectangle" x="1659" y="64" width="257" height="160" guid="5E3E76E3-431E-E1E1-B26C-930B32DB8AB1" /&gt;
	&lt;/shapes&gt;
&lt;/level&gt;</pre>
<p>It looks a bit complicated, but it's really not at all.  First of all, notice that I've only included a single line for each tag.  In reality, the entire file is over 1000 lines long (don't worry, Lua does all of that for us!).   On line 1 you can see that the root node for the entire XML file is called <strong>level</strong>.  This could be called anything, usually it's just <strong>&lt;xml&gt;</strong> but in this case I went with something that made sense to me.<span id="more-715"></span></p>
<h2>The main tags</h2>
<p>Within that root level tag, there are only 3 other main tags:</p>
<p><strong>&lt;tiles&gt;</strong></p>
<pre class="brush: xml;">&lt;tiles layer="template4" x="1440" y="0" width="480" height="480" tileWidth="32" tileHeight="32" widthInTiles="15" heightInTiles="15" &gt;</pre>
<p><strong> </strong>This contains all of the tilemap information for the level.  Each time within DAME that you click on the canvas and paint a tile (or use the tile matrix tool), it will be exported into the xml file within this tag.  More on that in a second.  Note the attributes within this tag:</p>
<ul>
<li><strong>layer </strong>- this is name of the layer within DAME.  For this part of the tutorial, we will just focus on "template4" because it has tiles, sprites and shapes that we will be using to spawn entities (as they are called in FlashPunk).</li>
<li><strong>x / y</strong> - This is the x/y offset within DAME.  We won't be using this number to place the tiles, but actually the sprites.  That may be a little confusing, but it's simply because DAME editor does not let you set the same properties on a sprite or shape layer, as you can on a tilemap layer.</li>
<li><strong>width / height</strong> - The dimensions of the map in pixels.  Although this could be calculated in AS3, this is handy to have as an attribute for reading through the XML code.  It also saves us the effort of figuring it out in code.</li>
<li><strong>tileWidth / tileHeight</strong> - More obvious sounding variables (in an ongoing effort to write self-commenting code) imply that these are simply the size in pixels of the tiles used.</li>
<li><strong>widthInTiles / heightInTiles</strong> - Again, this may seem redundant since we could calculate this in code from the information already provided.  It could be helpful to have for a few reasons though, so I've included it.</li>
</ul>
<p><strong>&lt;sprites&gt;</strong></p>
<pre class="brush: xml;">&lt;sprites layer="template4"&gt;</pre>
<p>Not surprisingly, this tag contains all of the sprites within the level.  As mentioned above, the <strong>&lt;tiles&gt;</strong> tag actually has all of the offset information needed to position the sprites.  The <strong>&lt;sprites&gt;</strong> tag only has one attribute actually: <strong>layer</strong>, which is set to "<strong>template4</strong>."</p>
<p><strong>&lt;shapes&gt;</strong></p>
<pre class="brush: xml;">&lt;shapes layer="template4"&gt;</pre>
<p>Just like the <strong>&lt;sprites&gt;</strong> tag, shapes gets it's offset information from the <strong>&lt;tiles&gt;</strong> tag with the same layer name, "<strong>template4</strong>."</p>
<h2>The Child Tags</h2>
<p>We're almost done covering the xml format!  Within each of the main parent tags, there are child tags.  For <strong>&lt;tiles&gt;</strong> there is <strong>&lt;tile&gt;</strong>, for <strong>&lt;sprites&gt;</strong> there is <strong>&lt;sprite&gt;</strong> and for <strong>&lt;shapes&gt;</strong> there is <strong>&lt;shape&gt;</strong>.  Let's go over each one, since this is where all the important stuff is:</p>
<p><strong>&lt;tile&gt;</strong></p>
<pre class="brush: xml;">&lt;tile tx="96" ty="0" x="0" y="0"/&gt;</pre>
<p>One of these tags is created each time you paint a tile within DAME.  There are only 4 attributes, which are all very straight forward:</p>
<ul>
<li><strong>tx / ty</strong> - This refers to the position of the tile image used within the tileset, in pixels.  In the example above, <strong>tx</strong> is 96 (pixels), which means it's 3 tiles over (the red bricks).  Since it may be hard to explain with text alone, here is an image to give you an better idea:<br style="clear: both;" /><img class="alignnone size-full wp-image-727" style="padding: 10px 0;" title="flashpunk-bgtiles-txty" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-bgtiles-txty.gif" alt="" width="800" height="80" /></li>
<li><strong>x / y</strong> - These are the actual coordinates of each tile, relative to the tilemap.  In the provided example, x and y are both 0, meaning that this tile will be placed in the top left corner of the tilemap.</li>
</ul>
<p><strong>&lt;sprite&gt;</strong></p>
<pre class="brush: xml;">&lt;sprite className="FlyingPig" x="1843" y="1" width="60" height="51" spawnShape="5E3E76E3-431E-E1E1-B26C-930B32DB8AB1" spawnAmount="5" /&gt;</pre>
<p>For the sprite example, let's look at this flying pig.  Out of all the different elements within the XML file, the <strong>&lt;tiles&gt;</strong> (plural) and <strong>&lt;sprite&gt;</strong> (non-plural) tags will usually have the most attributes (at least the way I've coded it).</p>
<p><img class="alignnone size-full wp-image-732" title="flashpunk-dame-tutorial-sprite-properties" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-sprite-properties.jpg" alt="" width="684" height="286" /></p>
<ul>
<li><strong>className</strong> - This is set within each sprite's properties inside of DAME, in the class field.  In flash we will be using this to reference classes of the same name.  In this example, it's "FlyingPig" which will correspond with <strong>FlyingPig.as</strong> in a later part to this series.</li>
<li><strong>x / y</strong> - The position of the sprite, however notice that this is not relative to the tilemap.  DAME treats all sprites as if they were positioned absolutely (forgive me using CSS terminology) instead of relatively.  This is why we will use the x attribute within the corresponding <strong>&lt;tiles&gt;</strong> tag, to figure out where to place the sprite within the tilemap.</li>
<li><strong>width / height</strong> - DAME allows you to resize (and even rotate) sprites within the editor.  We won't be doing that in this tutorial, however it's very helpful to know how big the sprites are before loading them into memory.  By setting these attributes, we will know exactly how big to make hitboxes, masks and etc.</li>
<li><strong>spawnShape / spawnAmount</strong> - Unlike the rest of the attributes listed so far, which are generated by default in DAME, spawnShape and spawnAmount were custom properties, created within the editor.  <strong>spawnShape </strong>refers to the GUID of a shape object within DAME (explained below in just a moment).  The spawnShape will be used to randomly place the sprite somewhere within the bounds of that shape.  The <strong>spawnAmount </strong>attribute will tell Flash how many of these sprites (in this case, Flying Pigs) to spawn within the spawn area.</li>
</ul>
<p><strong>&lt;shape&gt;</strong></p>
<pre class="brush: xml;">&lt;shape type="rectangle" x="1659" y="64" width="257" height="160" guid="5E3E76E3-431E-E1E1-B26C-930B32DB8AB1" /&gt;</pre>
<p>Finally, this is the last element to look at.  While a circle is used for example in this project, there is no code to support using circles as spawnShapes.  So let's take a look at a rectangle, which is being used as a spawnShape.</p>
<ul>
<li><strong>x / y</strong> - Just like our <strong>&lt;sprite&gt;</strong> tag, this is an absolute position of the shape, which will use the <strong>&lt;tiles&gt;</strong> position to offset within the code.</li>
<li><strong>width / height</strong> - Every rectangle needs the bare minimum of requirements, and this one is no exception.</li>
<li><strong>guid</strong> - This is a value that DAME automatically calculates for all objects created within the editor.  In our example, I've decided to export the <strong>guid </strong>value for just shapes, but could have exported the guid for all elements if needed.  Notice the <strong>guid </strong>of this shape, is the guid being referenced in the <strong>spawnShape </strong>attribute from the <strong>&lt;sprite&gt;</strong> tag above.</li>
</ul>
<p>For a visual example of whats going on here, let's look at this template within DAME:</p>
<p><img class="alignnone size-full wp-image-733" title="flashpunk-dame-tutorial-sprite-properties-editor" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-sprite-properties-editor.jpg" alt="" width="794" height="620" /></p>
<p>The FlyingPig <strong>&lt;sprite&gt;</strong> in this example, is the one you see in the top right of the template.  The <strong>&lt;shape&gt;</strong> being used as a <strong>spawnShape </strong>for the Flying Pig, is the rectangle right below him (or her).  You can also see by the marquee, that the FlyingPig sprite is selected within the DAME editor, and there are two custom properties (on the bottom left).  This is where spawnShape and spawnAmount are defined.</p>
<h2>Conclusion of Part 3</h2>
<p>Phew, I wasn't sure how much detail I wanted to go into with this XML file, but turns out, I wanted quite a bit.  You should now understand how to create a level within DAME editor, and what that information will look like when it comes out of DAME.  The next step of this tutorial will be to explain exactly <em>how</em> all of this information is converted, using Lua (which is <em>not </em>an acronym).</p>
<p><a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-4">Continue to Part 4</a></p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FlashPunk, DAME and Lua Tutorial (Part 2)</title>
		<link>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-2/</link>
		<comments>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-2/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 11:10:23 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[FPDameTemplates]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=683</guid>
		<description><![CDATA[Welcome back to the next step in this tutorial series.  Here are the first two parts, where I covered the different software and languages being used. The last part briefly went over the level design concept, so let's go further into each "Template" before moving on. Template 1 Each "template" in this tutorial consists of [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome back to the next step in this tutorial series.  Here are the <a href="http://producerism.com/blog/making-a-game-with-flashpunk-dame-and-lua/">first</a> <a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-1/">two</a> parts, where I covered the different software and languages being used.</p>
<p>The last part briefly went over the level design concept, so let's go further into each "Template" before moving on.</p>
<h2>Template 1</h2>
<p>Each "template" in this tutorial consists of a tilemaps layer, sprites layer, and shapes layer.  The first four templates are all 15 x 15 tiles.  Since each tile is 32px wide, templates 1-4 are all 480px by 480px.  In this first image, you are seeing the tilemap, sprite and shape layers titled "template1."  As you can see, it consists of a few obstacles on the tilemap layer, four balloons and two clouds on the sprite layer, and a circle on the shape layer.  The circle will not be used, other than to show how we export it into XML via Lua.   Also, notice the settings window on the right, which reflects the 15x15 tiles in the tilemap, and the 32px by 32px size of the tiles.  The rest of the settings are either default, or calculated automatically by DAME.</p>
<p><img title="flashpunk-dame-tutorial-level-1" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-level-11.gif" alt="" width="800" height="410" /><span id="more-683"></span></p>
<h2>Template 2</h2>
<p>Moving on, this template consists of the tilemap layer and sprite layer named "template2."  As you can see in the settings, every thing is about the same, except for the "<strong>x</strong>" variable, which is set to 480.  This is the offset of the map.  Since the last map was 480px wide, we need to offset template2 in order to see all the templates side-by-side within DAME.  The "<strong>x unit</strong>" parameter is automatically calculated by DAME.  It's basically the same offset, but in tiles.</p>
<p><img class="alignnone size-full wp-image-695" title="flashpunk-dame-tutorial-level-2" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-level-21.gif" alt="" width="800" height="410" /></p>
<h2>Template 3</h2>
<p>If you are detecting a pattern, you may already know that this image shows the tilemap and sprite layers named "template3."  This map has a flying horse, and a UFO.  As far as DAME is concerned, these two enemy objects are just different sprite images.  Again, all of the settings are very similar to the last few screenshots, but you can see the "<strong>x</strong>" variable has increased again.  This is the third map, and since the first two maps were 480px wide each, 480 x 2 = 960.  Again, the "<strong>x unit</strong>" parameter is calculated automatically.</p>
<p><img class="alignnone size-full wp-image-696" title="flashpunk-dame-tutorial-level-3" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-level-31.gif" alt="" width="800" height="410" /></p>
<h2>Template 4</h2>
<p>This is the last 480x480 template, and again the settings are following the same pattern as the first 3.  What's different is that this template contains two different shapes.  You can see the semi-transparent rectangles on the top right and bottom right of the template.  These don't mean anything special within DAME, but within the ActionScript code, we will translate these into spawning areas.  Instead of just placing enemy sprites on the map manually, maybe we want to make sure that they appear in a random position, but within certain bounds.</p>
<p><img class="alignnone size-full wp-image-697" title="flashpunk-dame-tutorial-level-4" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-level-41.gif" alt="" width="800" height="410" /></p>
<p>There are many different ways we could link an enemy object (in this case, the flying pig) to a shape.  In fact, DAME has a cool linking feature where you can just connect two objects together - sprites, shapes and paths can all be linked to each other.  However, the getting the links to export in Lua was taking more time than I wanted, so I took a different route.  By right clicking on any sprite or shape within the DAME editor, you will get a pop-up menu with a few options.  Each object inside of DAME has a unique id, which you can copy to the clipboard by selecting the "<strong>Copy GUID</strong>" option.  In this case, I've clicked on the rectangle I want to use as a spawning area for the flying pig sprite.  Notice that the shape layer called "template1" is selected in the layers tab.  Ignore the name, as the shape layer applies to all maps - but note that in order to select shapes or sprites, the layer they are on must be selected, and you must be using the selection tool (to the right of the paintbrush, which looks like four arrows points in all directions).</p>
<p><img class="alignnone size-full wp-image-688" title="flashpunk-dame-tutorial-level-4-shape-guid" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-level-4-shape-guid.gif" alt="" width="688" height="471" /></p>
<p>Now that we've copied the GUID of the rectangle we're using as a spawning area to the clipboard, we select the sprite layer that our flying pig is on, and then select him.  On the bottom right of the DAME editor, there are options to add and remove properties.  I've simply clicked  "<strong>Add Property</strong>," then added a property called "<strong>spawnShape</strong>" and pasted in the GUID on the clipboard.  Again, this doesn't mean anything to DAME - it's up to us to export that information into an XML with Lua, and then make it happen with ActionScript.  You can also see I added a property called "<strong>spawnAmount</strong>," which I've set to 5.   This will create 5 different flying pig sprites randomly within the spawnShape area (the rectangle right below the pig).</p>
<p><img class="alignnone size-full wp-image-689" title="flashpunk-dame-tutorial-level-4-spawnShape" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-level-4-spawnShape.gif" alt="" width="688" height="471" /></p>
<h2>Template 5</h2>
<p>That last template was probably the most complicated.  These next two are simple, and used to demonstrate that the maps can be of different widths.</p>
<p><img class="alignnone size-full wp-image-690" title="flashpunk-dame-tutorial-level-5" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-level-5.jpg" alt="" width="800" height="256" /></p>
<p>The settings for this layer look just like the rest.  As you can see, the "<strong>x</strong>" and "<strong>x unit</strong>" offset variables are still increasing.  The first four templates were all 480 x 480.  Since 4 x 480px = 1920px, that's what we set "<strong>x</strong>" to.  You can also see that this template is much bigger than the previous ones, with the "<strong>width</strong>" set to 47 (tiles).</p>
<p><img class="alignnone size-full wp-image-691" title="flashpunk-dame-tutorial-level-5-settings" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-level-5-settings.jpg" alt="" width="406" height="346" /></p>
<h2>Template 6</h2>
<p>This tilemap layer is even simpler.  In fact, it doesn't have any sprites on it - and by looking at the layers panel, you will notice that I haven't even created a sprite layer called "template6."  When we get all of this into Flash, we'll just be checking for a tilemap layer, and then if there's a sprite layer to go along with it, we parse that too.  If not, we'll just move along.  More on that later.  Just take a look at the last template in this file:</p>
<p><img class="alignnone size-full wp-image-692" title="flashpunk-dame-tutorial-level-6" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-level-6.jpg" alt="" width="800" height="240" /></p>
<p>Again, very simple, and the settings are similar to the previous 5.  Our last offset was 1920, but the last template was 47 tiles wide.  47 tiles x 32 pixels = 1504 pixels, and 1504 + 1920 (the offset of template 5) = 3424.  And look at that, "<strong>x unit</strong>" has gone and calculated itself for us again, how thoughtful.</p>
<p><img class="alignnone size-full wp-image-693" title="flashpunk-dame-tutorial-level-6-settings" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-level-6-settings.jpg" alt="" width="406" height="346" /></p>
<h2>Part 2 Conclusion</h2>
<p>So in this part we went over each template within the FPDameTemplatesTutorial.dam file in detail.  In the next part we will actually export the file into XML, and cover the XML string that is generated by Lua.  Hope that this part wasn't too redundant - I just felt that having a good idea of what I had in mind when designing these maps would help as we get a bit deeper into the process.  Let me know in the comments what you think!</p>
<p><a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-3">Continue to Part 3</a></p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>FlashPunk, DAME and Lua Tutorial (Part 1)</title>
		<link>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-1/</link>
		<comments>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-1/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 02:17:56 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[FPDameTemplates]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=663</guid>
		<description><![CDATA[If you haven't read the first part of this tutorial, do that now (or don't if you just want to jump right in).  The last post was a long explanation of how I ended up with the specific combination of FlashPunk and DAME (and Lua).  In order to follow along, I will assume are either [...]]]></description>
			<content:encoded><![CDATA[<p>If you haven't read <a href="http://producerism.com/blog/making-a-game-with-flashpunk-dame-and-lua/">the first part of this tutorial</a>, do that now (or don't if you just want to jump right in).  The last post was a long explanation of how I ended up with the specific combination of FlashPunk and DAME (and Lua).  In order to follow along, I will assume are either using <a href="http://www.flashdevelop.org">FlashDevelop</a>, or understand how to use this tutorial with whatever IDE you are using (Flash CS3/4/5, Flash Builder, etc.).  For instructions on setting up FlashDevelop with FlashPunk, check out <a href="http://www.brighthub.com/hubfolio/matthew-casperson/articles/66640.aspx">this tutorial</a>.  I will also assume you already understand the basic concepts of inheritance, and extending classes in ActionScript 3.  If not, feel free to follow along anyways, but I recommend <a href="http://www.untoldentertainment.com/blog/2009/08/25/tutorial-understanding-classes-in-as3-part-1/">this tutorial</a>, and <a href="http://www.amazon.com/exec/obidos/ASIN/0596526946">this book</a>.  And just for a quick peak at what we will be creating, here is a screenshot:</p>
<p><img class="alignnone size-full wp-image-664" title="flashpunk-dame-tutorial-screenshot" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-screenshot.jpg" alt="" width="800" height="440" /><span id="more-663"></span></p>
<p>Over the years, I've learned many things the hard way - programming and game design not excluded.  As with almost anything, having an idea of what your final product will be is essential... otherwise, how will you know when you are done?  I'm sure everybody is different, but for me, having some kind of measurable goal really helps keep focus.  For this tutorial, the goal isn't to make a game, but to integrate FlashPunk and DAME Editor seamlessly.  The final result will be an actionscript project with all the components needed to make a game (enemies, items, player, controls, level design, etc.), along with some great extra features like random spawning areas, and an endless random level generator (it sounds fancy because it is!).  Just to point it out now, we won't actually be going into the specifics of DAME, Lua or Flash in this part of the tutorial.  Instead, we will cover all the moving parts, and explain how they work together.  In the next parts of this tutorial I will actually explain each step, along with all the code in detail.</p>
<p>To get started, you will need to download two things:</p>
<ol>
<li><a href="http://producerism.com/wp-content/uploads/2011/01/FPDameTemplatesTutorial.zip">FPDameTemplatesTutorial.zip</a> (source, assets, DAME project, Lua scripts)</li>
<li><a href="http://dambots.com/dame-editor/">DAME Editor</a></li>
</ol>
<p>The entire project breaks down into five specific components:</p>
<ol>
<li>Artwork Assets (sprites and tiles)</li>
<li>Level Design (via DAME)</li>
<li>Lua Export Script</li>
<li>XML Level (output by DAME)</li>
<li>Flash Project</li>
</ol>
<h2>Artwork Assets</h2>
<p>It seems that a majority of games created with FlashPunk and Flixel are tile-based, and use low-res pixel art.  The main reason for this is that most of those games are designed to a very small resolution (like 320 x 240) and then scaled up in flash (to 640 x 480).  This allows the game to run extremely fast, since flash tends to (mis)use lots of memory with loads of hi-res graphics.  This is why OGMO (and other tile editors) are such great tools for tile-based games.  Where traditional tile-editors fall short (by design, not by fault) is dealing with non-tile based objects, like sprites, paths, shapes and the ability to link objects together.  DAME handles all of that with ease.</p>
<p>Extract the project file you downloaded above, and navigate to the assets folder.  There you will see a folder for "sprites" and another for "tiles."  The tiles file is just a typical set of 8 different 32x32 tiles.  In the sprites folder however, are some non-tile based images, including sprite sheets - a flying pig, and a flying horse.  Also notice that none of these images are lo-res or pixel art.  In fact they all have transparent backgrounds, and complex masks (alpha mattes).</p>
<p><img class="alignnone size-full wp-image-666" title="flashpunk-dame-tutorial-assets-screenshot" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-assets-screenshot.jpg" alt="" width="800" height="156" /></p>
<h2>Level Design</h2>
<p>Since we have all of the art assets we need, the next step is to design a level.  Open up DAME Editor, and load the DAME project file (FPDameTemplatesTutorial.dam).  DAME project files are essentially just XML files.  In fact, we will be opening up this project file in a text editor later, and making a small, one-time change.  But first, take a look at the different elements that make up this project.  In the layers tab on the left, there are three groups: maps, sprites and shapes.  The maps group will contain all of our tile-map layers.  In the game, these can either be used as backgrounds, or as actual levels, complete with collision detection.  The sprites group contains all of the layers which contain enemies and items.  The shapes group just has one layer, and will store shapes used for randomly spawning sprites (enemies and items).  Please notice that each sprite layer shares the name with a map layer (template1, template2, etc.).  More on this later.</p>
<p><img class="alignnone size-full wp-image-667" title="flashpunk-dame-tutorial-dame-screenshot" src="http://producerism.com/wp-content/uploads/2011/01/flashpunk-dame-tutorial-dame-screenshot.jpg" alt="" width="800" height="418" /></p>
<p>If you click on the "sprites" tab (next to "Layers"), you will see a list of all sprites used in the project (see right portion of screenshot above).  Finally, the main portion of the screen is devoted to the actual level design.  I will not explain how to create maps within DAME - for that, follow <a href="http://www.brighthub.com/hubfolio/matthew-casperson/articles/101670.aspx">this tutorial</a>.  I assure you, it's incredibly easy - especially since we won't be making use of any advanced features in this tutorial like paths, painting, text or linking.  Once you get a good understanding of how to create maps in DAME, and what the difference is between a sprite layer and a map layer, close DAME as we will be editing the <strong>FPDameTemplatesTutorial.dam</strong> project file in the next part of this FlashPunk, DAME and Lua tutorial series.</p>
<p><a href="http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-2/">Continue to Part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>FlashPunk, DAME and Lua Tutorial (Part 0)</title>
		<link>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-0/</link>
		<comments>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-0/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 13:08:51 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[FPDameTemplates]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=640</guid>
		<description><![CDATA[This is a fairly lengthy post, which is an introduction to the next tutorial series I will be posting.  If you don't care about the how, when or why, here is the quick version:  Motivated to develop more flash games, I tried learning PushButtonEngine for the nth time, but still struggled grasping all of the [...]]]></description>
			<content:encoded><![CDATA[<p>This is a fairly lengthy post, which is an introduction to the next tutorial series I will be posting.  If you don't care about the how, when or why, here is the quick version:  Motivated to develop more flash games, I tried learning PushButtonEngine for the nth time, but still struggled grasping all of the concepts.  Then I tried learning Flixel for the nth time, but still struggled with committing all the classes and workflow to memory.  In attempt to keep trying to learn Flixel, I saw a post about <a href="http://www.brighthub.com/hubfolio/matthew-casperson/articles/101674.aspx">creating a level with Flixel and  DAME</a>.  Unfortunately, the tutorial ended before it actually got into Flixel, but I really fell in love with this app called the <a href="http://dambots.com/dame-editor/">DAME Editor</a>.  After noticing that DAME came with a FlashPunk exporter, and after realizing I had never really tried FlashPunk, I decided to give that engine a go as well.  Turns out, FlashPunk was just what I had been looking for, and now I've decided to write a tutorial on using FlashPunk, DAME, and incidentally, Lua.  Phew.</p>
<p>Well, that was the short version.  For the long version, please read on:<span id="more-640"></span></p>
<p>It's rare, but luckily a project came up which has allowed me to focus more on game development.  In the past, I've made very simple games from scratch, with the exception of one using a <a href="http://www.box2dflash.org/">Flash Box2D port</a>, which in many ways was still pretty simple. At <a href="http://www.gdconline.com/">GDC Online</a> in October of 2010, I sat in on a talk from <a href="http://blog.bengarney.com/">Ben Garney</a>, which was a very brief overview of the <a href="http://pushbuttonengine.com/">PushButtonEngine</a> for Flash.  Even though I had already seen the same information from the <a href="http://www.youtube.com/user/kmprssr">PBE videos on youtube</a>, being able to ask a few questions and talk with other developers there really gave me motivation to start going through the tutorials.</p>
<p><a href="http://pushbuttonengine.com"><img class="alignnone size-full wp-image-641" title="PushButtonEngine" src="http://producerism.com/wp-content/uploads/2011/01/pbe_logo.jpg" alt="" width="606" height="105" /></a></p>
<p>After learning a bit about the engine, and really falling in love with whole composition vs inheritance approach, I still felt a little overwhelmed with the workflow.  I could follow along with most of the tutorials I found online, however it seemed that the whole XML based approach was the way to go.  With limited examples provided, it was hard to get beyond any unexpected issues that came up.  I tried Flixel again, but like all the other times I've experimented with Flixel, it seemed like overkill for getting a quick and simple game up and running, in a way that made sense to me.</p>
<p><a href="http://flixel.org"><img class="alignnone size-full wp-image-644" title="Flixel" src="http://producerism.com/wp-content/uploads/2011/01/flixel_logo.jpg" alt="" width="606" height="105" /></a></p>
<p>Searching for further tutorials, I came across a link that mentioned <a href="http://www.brighthub.com/hubfolio/matthew-casperson/articles/101674.aspx">creating a level with Flixel and  DAME</a>.  The tutorial didn't ever cover Flixel, and focused mostly on a tile map editor called DAME.  Well, for a few hours I lost focus on reviewing game engines, and instead became fascinated with the amount of features, and ease of use within this DAME Editor.  I also noticed that in the various formats it exported to, besides Flixel it also supported FlashPunk.</p>
<p><a href="http://flashpunk.net/"><img class="alignnone size-full wp-image-648" title="FlashPunk" src="http://producerism.com/wp-content/uploads/2011/01/fp-320x80_badge.png" alt="" width="320" height="80" /></a></p>
<p>I'd always noticed the FlashPunk logo on the bottom of Flixel's homepage, which reads:</p>
<blockquote><p>If you are allergic to flixel for one reason or another, don’t give up! Check out ChevyRay’s library <a href="http://flashpunk.net/">FlashPunk</a> instead, it’s awesome!</p></blockquote>
<p>Seeing as how I hadn't been successful with PushButtonEngine or Flixel yet, I figured there was nothing to lose by checking it out.  I followed along all the <a href="http://flashpunk.net/?p=tutorials">text and video tutorials on FlashPunk</a>, followed by a few more I found on <a href="http://thedoglion.wordpress.com/category/programming/game-development/flashpunk-tutorials/">The Doglion</a>.  I noticed that almost all of the other FlashPunk developers on the forums, and on IRC all use <a href="http://ogmoeditor.com/">OGMO Editor</a> for tile maps.  It seemed to do the trick, but after playing with DAME, it just couldn't compare in features.</p>
<p><a href="http://ogmoeditor.com/"><img class="alignnone size-full wp-image-645" title="ogmo-screen1" src="http://producerism.com/wp-content/uploads/2011/01/ogmo-screen1.png" alt="" width="480" height="360" /></a></p>
<p>After following through the OGMO and FlashPunk tutorials, I had everything working pretty quickly.  And more importantly, I felt like I understand all the pieces that were working together within the engine, since they were designed in a way very similar to my own thinking.  I tried using the FlashPunk exporter in DAME, and although it exported a few files as expected, I had no idea how to use all of the files that were generated.  So instead of moving on, I decided to first make an XML exporter to reflect the output of an OGMO map.  Being my first encounter with scripting in Lua, I did fairly well - the map I designed loaded up, just as if I had made it in OGMO.</p>
<p><a href="http://dambots.com/dame-editor/"><img class="alignnone size-full wp-image-649" title="DAME" src="http://producerism.com/wp-content/uploads/2011/01/DAMEscreenshot1.jpg" alt="" width="650" height="417" /></a></p>
<p>The next step, was to try and integrate the more advanced features of DAME into a FlashPunk game.  While not complete by any means, I've managed to create a custom exporter which handles tiles, sprites, custom properties and even random spawning areas.  Features I'm still working on are paths, links, and a few other things.  That being said, I'm really excited about the workflow I've been able to achieve between FlashPunk and DAME, and decided to start a new tutorial series on the entire process, starting with DAME, then Lua, then FlashPunk.  Not sure how many parts the tutorial will be in, but probably at least 4.  Anyways, hope some of you are as excited as I am about it!   Stay tuned and subscribe to my blog to follow along!</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/flashpunk-dame-and-lua-tutorial-part-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tom-as3-gotchi (Flash Game Tutorial) Part 4</title>
		<link>http://producerism.com/blog/tom-as3-gotchi-flash-game-tutorial-part-4/</link>
		<comments>http://producerism.com/blog/tom-as3-gotchi-flash-game-tutorial-part-4/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 15:12:19 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Tom-as3-gotchi]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=601</guid>
		<description><![CDATA[For the fourth part to this tutorial, as promised, I will start introducing some graphics.  I started by sketching out a very rough example of the room our virtual character will live in, then I sketched out a gui - which for now is really just a rectangular frame. After a bit of time using my Wacom [...]]]></description>
			<content:encoded><![CDATA[<p>For the fourth part to this tutorial, as promised, I will start introducing some graphics.  I started by sketching out a very rough example of the room our virtual character will live in, then I sketched out a <a href="http://en.wikipedia.org/wiki/Graphical_user_interface">gui</a> - which for now is really just a rectangular frame.  </p>
<p><img class=" size-medium wp-image-606" title="tom-as3-gotchi-sketch1" src="http://producerism.com/wp-content/uploads/2010/06/tom-as3-gotchi-sketch1-300x180.jpg" alt="" width="300" height="180" /> <img class="size-medium wp-image-602" title="tom-as3-gotchi-sketch-frame1" src="http://producerism.com/wp-content/uploads/2010/06/tom-as3-gotchi-sketch-frame1-300x214.jpg" alt="" width="300" height="214" /> </p>
<p>After a bit of time using my Wacom in the Flash IDE, I recreated the sketches in vector format, and then separated them into MovieClips and Graphic symbols.  </p>
<p><img class="aligncenter size-full wp-image-605" title="tom-as3-gotchi-screenshot1" src="http://producerism.com/wp-content/uploads/2010/06/tom-as3-gotchi-screenshot1.jpg" alt="" width="640" height="480" /> </p>
<p><span id="more-601"></span>Here is an example of how I decided to organize all of the different assets for now.  Notice that two of the items, Gui and gauge, have linkage properties, which is why their "Export" property isn't blank like the rest of the symbols in the library.  </p>
<p><img class="aligncenter size-full wp-image-604" title="tom-as3-gotchi-library1" src="http://producerism.com/wp-content/uploads/2010/06/tom-as3-gotchi-library1.jpg" alt="" width="332" height="625" /></p>
<p>First, let's take a look at the code and assets in the Gui class.  Here's a screenshot of the assets, and their instance names: </p>
<p><img class="aligncenter size-full wp-image-603" title="tom-as3-gotchi-gui-class" src="http://producerism.com/wp-content/uploads/2010/06/tom-as3-gotchi-gui-class.jpg" alt="" width="535" height="386" /> </p>
<p>And now, here is the code to go along with the Gui class:</p>
<pre class="brush:as3">package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	public class Gui extends MovieClip
	{
		// Event constants
		public static const APPLE_CLICKED:String = "apple clicked";
		public static const CHEESEBURGER_CLICKED:String = "cheeseburger clicked";

		// Gui elements
		public var age_txt:TextField;
		public var weight_txt:TextField;

		public var boredomGauge:Gauge;
		public var hungerGauge:Gauge;
		public var thirstGauge:Gauge;

		public var apple:MovieClip;
		public var cheeseburger:MovieClip;

		public function Gui()
		{
			// set labels
			boredomGauge.label.text = "Boredom";
			hungerGauge.label.text = "Hunger";
			thirstGauge.label.text = "Thirst";

			// add button function to apple
			apple.addEventListener(MouseEvent.CLICK, function(evt:Event) { dispatchEvent(new Event(APPLE_CLICKED)); }, false, 0, true);
			apple.buttonMode = true;
			apple.useHandCursor = true;

			// add button function to cheeseburger
			cheeseburger.addEventListener(MouseEvent.CLICK, function(evt:Event) { dispatchEvent(new Event(CHEESEBURGER_CLICKED)); }, false, 0, true);
			cheeseburger.buttonMode = true;
			cheeseburger.useHandCursor = true;
		}

		public function update($tom:Tom):void
		{
			// update all Gui fields based on $tom variable
			age_txt.text = String($tom.age);
			weight_txt.text = String($tom.weight);
			boredomGauge.value = $tom.boredom;
			hungerGauge.value = $tom.hunger;
			thirstGauge.value = $tom.thirst;
		}

	}

}</pre>
<p>Since it's all new, let's go through it line by line.  </p>
<p>First, you will notice two public static constants, <strong>APPLE_CLICKED</strong> and <strong>CHEESEBURGER_CLICKED</strong>, which will serve as temporary Event descriptions.  We then define our textfields, <strong>age_txt</strong> and <strong>weight_txt</strong>.  </p>
<p>Then we define the gauges, <strong>boredomGauge</strong>, <strong>hungerGauge</strong>, and <strong>thirstGauge</strong>, which make use of another new class, <strong>Gauge.as</strong>.  Finally, we need something to click on, which interacts with our character.  For now, I've created two simple MovieClips and cleverly named them <strong>apple </strong>and <strong>cheeseburger</strong>, but  in the future I will connect these to the <strong>Food.as class</strong>.  </p>
<p>Other than the declarations we just went over, there are only 2 functions to the Gui.as class right now, the constructor function, <strong>Gui()</strong>, and <strong>update()</strong>.  The constructor function is pretty simple, we just assign labels to the gauges.  Each item which uses the <strong>Gauge.as</strong> class is basically a MovieClip with certain child item, including a textfield named <strong>label</strong>.  Next, we add MouseEvent listeners to the <strong>apple </strong>and <strong>cheeseburger</strong> MovieClips, which in turn dispatch an event.  This may seem redundant, but it's one way of separating the logic in the Gui fro the game logic, which will reveal it's use as the project increases in complexity.  </p>
<p>The remaining function, <strong>update()</strong>, is used to refresh the gui to reflect all of the current values of the passed <strong>Tom.as</strong> object.  </p>
<p>For Part 5 we'll explore the Gauge.as class, and then see everything in action so far!</p>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/tom-as3-gotchi-flash-game-tutorial-part-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SlotMas3chine (Slot Machine AS3 Tutorial)</title>
		<link>http://producerism.com/blog/slotmas3chine-slot-machine-as3-tutorial/</link>
		<comments>http://producerism.com/blog/slotmas3chine-slot-machine-as3-tutorial/#comments</comments>
		<pubDate>Thu, 27 May 2010 17:48:49 +0000</pubDate>
		<dc:creator>T</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[SlotMas3chine]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://producerism.com/?p=587</guid>
		<description><![CDATA[I put together a quick example of a slot machine in AS3 in about 15 minutes, and under 100 lines.  It can still be optimized a great deal, and I will probably make some updates to this in the near future.  One of the requests of the example, was an ability to hold matching reels.  [...]]]></description>
			<content:encoded><![CDATA[<p>I put together a quick example of a slot machine in AS3 in about 15 minutes, and under 100 lines.  It can still be optimized a great deal, and I will probably make some updates to this in the near future.  One of the requests of the example, was an ability to <em>hold matching reels</em>.  So in this example, once 2 of the reels in the slot machine match, those will not respond to the<strong> spin()</strong> function anymore.  This will be changed around a bit future updates, to act more like a typical slot machine that does not have this feature.</p>
<p><a href="http://wonderfl.net/c/5BNK">here it is in action on wonderfl</a></p>
<p>The explanation (or tutorial) part of this post will be complete  soon.  I will also optimize the code in the next couple of posts.  Until then, take a look at the code and try to understand what's  going on.<span id="more-587"></span></p>
<pre class="brush:as3">package
{
    import flash.display.Sprite;

    public class SlotMachine extends Sprite {

        private var _credits:uint = 4; // start with $20

        private var _slotReel1:SlotReel;
        private var _slotReel2:SlotReel;
        private var _slotReel3:SlotReel;

        public function SlotMachine()
        {   

            _slotReel1 = new SlotReel();
            _slotReel2 = new SlotReel();
            _slotReel3 = new SlotReel();

            spinReels();
            spinReels();
            spinReels();
            spinReels();
        }

        private function spinReels():void
        {
            if (_credits)
            {
                _credits--; // costs $1 per spin

                _slotReel1.spin();
                _slotReel2.spin();
                _slotReel3.spin();

                // check for matches
                if (_slotReel1.value == _slotReel2.value &amp;&amp; _slotReel1.value == _slotReel3.value)
                {
                    trace("win!");
                    _credits += 1000;
                }
                else if (_slotReel1.value == _slotReel2.value)
                {
                    _slotReel1.hold = true;
                    _slotReel2.hold = true;
                }
                else if (_slotReel1.value == _slotReel3.value)
                {
                    _slotReel1.hold = true;
                    _slotReel3.hold = true;
                }
                else if (_slotReel2.value == _slotReel3.value)
                {
                    _slotReel2.hold = true;
                    _slotReel3.hold = true;
                }

                trace(_slotReel1.value + " " + _slotReel2.value + " " + _slotReel3.value+" credits left: "+_credits);
            } else {
                trace("out of credits!");
            }

        }

    }
}

import flash.display.MovieClip;

class SlotReel extends MovieClip {

    private var _numberOfSlotFrames:uint = 12;
    private var _currentSlotFrame:uint;
    public var hold:Boolean;

    public function SlotReel(){ super(); }

    public function spin():void
    {
        if (!hold)
        {
            _currentSlotFrame = Math.round(Math.random() * (_numberOfSlotFrames- 1) + 1);
            gotoAndStop(_currentSlotFrame);
        }
    }

    public function get value():uint { return _currentSlotFrame; }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://producerism.com/blog/slotmas3chine-slot-machine-as3-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)

Served from: producerism.com @ 2012-05-19 08:43:06 -->
