Creating_ProjectTemplates_featured

Whenever a countdown is announced to signal the beginning of a Global GameJam, Ludumdare Compo, 7-days FPS, Jam O’Clock, 0hrs jam or whatever it may be… there is no time to be wasted on setting up your project environment.

If you are like me, I have a few “goto” libraries that I just can’t live without. If you find yourself using the same Game Engine frameworks time and again for your GameJam entries or other projects, then this tutorial is for you!

Start by creating your Template Directory

Firstly, you must create a new Template Directory where you will store all your template files, so that FlashDevelop can find them, list it in the wizard and copy the files once you tell it to use your template. I find that the fastest way to do this is simply to duplicate an existing Project Template. Just select one that resembles the closest to what you have in mind.

For instance, I selected “120 ActionScript 3 – AS3 Project” found in:

  • C:\Program Files\FlashDevelop\Projects

… and then I pasted it in my FlashDevelop “User ” folder (on Windows 7):

  • %USERNAMEPROFILE%\AppData\Local\FlashDevelop\Projects

Once copied, you can rename it to something more meaningful that will indicate what the Template contains and will be easy to know it was created by you.

In my case, I renamed it to: “125 ActionScript 3 – AS3 Project (BigP)“.

Note: Once shown in the Template Wizard  panel, the prefix number (ex: 125) will not be displayed. I’m guessing it is only used for sorting purposes (although any projects created in your FlashDevelop User directory will all be displayed at the END of the template list). The rest follows the same naming convention, for the exception of my alias (ex: BigP) entered in parentheses at the end of the folder name.

Configure the Project Settings file

Depending on your needs, you may want to make modifications to the Project Settings file in order to specify which Flash version to use, which SWC files to include in the class library, or even the dimensions you will typically use in your projects.

If you open up the Project.as3proj file and look into the <output> element, you can modify the dimensions of the output SWF file and the Flash Player version to target (major and minor).

    <movie width="800" />
    <movie height="600" />
    <movie version="11" />
    <movie minorVersion="2" />

Including SWC files in your Project

Further down in the Project.as3proj file, you can add a list of SWC files your Project will include. Start by locating the </build> end-tag, and then you can add your SWCs like so:

    ...
  </build>
  <!-- SWC Include Libraries -->
  <includeLibraries>
    <!-- example: <element path="..." /> -->
  </includeLibraries>
  <!-- SWC Libraries -->
  <libraryPaths>
    <element path="lib\as3-signals.swc" /> <!-- Signals -->
    <element path="lib\greensock.swc" /> <!-- TweenLite -->
    <element path="lib\flixel.swc" /> <!-- Flixel -->
  </libraryPaths>
  <!-- External Libraries -->
  <externalLibraryPaths>
    <!-- example: <element path="..." /> -->
  </externalLibraryPaths>
  ...

Notice the three (3) SWCs are expected to be included in the “lib” folder of your Project Template. Let’s do that!

Note: Creating SWC files won’t be covered in this tutorial, but if you would like more information on this part, let me know in the comments below!

Preparing Classes Ready-to-Use

To shave off a few extra minutes of Project preparation, you can define ActionScript classes that will already have any necessary initialization code, automatically fill in the User’s author information in AsDoc and even maintain the given developer’s coding style in the process (ex: Curly Braces on same line vs. next line).

The Template ActionScript files are typically located inside:

  • (Your_Project_Template_Dir)\src\$(PackagePath)

One important thing to remember, is that within this folder… some special reserved keywords / labels exists to “paste” predefined information in the file. This happens while FlashDevelop copies the template files for your new projects. An example of a label would be $(DefaultUser), which outputs the User name (remember the first time you launch FlashDevelop and it prompts you for your First and Last name? This is it!)

Here is what my “Main.as” template file looks like (with some Flixel “prep” code):

package $(PackageName)$(CSLB){
	import com.game.states.StateStart;
	import flash.display.Sprite;
	import flash.events.Event;
	import org.flixel.FlxGame;
	
	/**
	$(CBI)* ...
	$(CBI)* @author $(DefaultUser)
	$(CBI)*/
	[SWF(width=640,height=480,frameRate=30)]
	public class Main extends FlxGame $(CSLB){
		
		public function Main():void $(CSLB){
			super(640, 480, StateStart);
		}
		
	}
	
}

As for the rest, I prepared a whole folder-structure and a few other ActionScript files to jumpstart any Flixel projects I intend to work on in the future.

Conclusion

Creating new Project Templates is fairly easy, just remember to append *.template to the very end of your ActionScript files, and you will be golden!

What Project Templates would you like to create?