Skip to content

Generating a Basic Template With flx.py

bunnyhero edited this page Mar 6, 2011 · 11 revisions

NOTE: This article assumes that you have Python installed. Most Macs ship with Python, but if you are on windows you may need to install it. Check out the official Python downloads page for more information.

I was getting tired of copy-pasting files when all my flixel games had the same basic structure, so this morning I wrote a little py script that can go through and do most of that dirty work on its own. I’ve uploaded it and put together this little walkthrough so that you guys can use it to cheat too!

AUTOMATION

STEP 1: Do Steps 1 and 2 only from the Hello World tutorial. That is, create a new project and add the flixel API to the build path. Stop when you get to Step 3. We’re going to automate.

STEP 2: Download flx.py from flixel.org

STEP 3: Put it in your workspace folder; that is, the folder that contains all your various flash projects:

STEP 4: Open a terminal, navigate to your workspace folder, and enter this command, where ‘MyNewGame’ is the name of your new project (e.g. FlxInvaders):

python flx.py MyNewGame

STEP 5: That’s it, there is no step 5! You just auto-generated the basic game class, preloader, game state, and even a simple title screen:

CUSTOMIZATION

If you’re feeling sassy, you can open the script in a text editor and easily customize it to your liking. At the top of the script you’ll notice a bunch of presets:

#BASIC SCRIPT PRESETS
width = 320			# Width of your game in 'true' pixels (ignoring zoom)
height = 240			# Height of your game in 'true' pixels
zoom = 2			# How chunky you want your pixels
src = 'src/'			# Name of the source folder under the project folder
preloader = 'Preloader'		# Name of the preloader class
flexBuilder = True		# Whether or not to generate a Default.css file
menuState = 'MenuState'		# Name of menu state class
playState = 'PlayState'		# Name of play state class

Most simple tweaks to the script can be done to this block without having to mess with the actual generator code. The generator code is quite simple though, and you’re more than welcome to mess with that too! Good luck!

Sassiness

Awesome script! I’ve made some changes for the Mac + mxmlc + Make build chain (with Flixel’s root at FLIXEL_HOME/lib) and optional support for package hierarchy in this gist. — Joe Osborn