How to disable automatic pausing in Flixel 2.5

05/08/2011

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 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)

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);
		}

	}

}

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.

comments

How to: Develop in Corona SDK on Windows

05/01/2011

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 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:


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 less than 10 lines of code. read more...

comments

Debugging PHP with PHPStorm and Netbeans

04/26/2011

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). read more...

comments

FlashPunk, DAME and Lua Tutorial (Part 5)

04/17/2011

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 part 0, after experimenting with Flixel and PushButton, FlashPunk just seemed to work closer to the way I design games in my head (and on paper).

The overall structure of the code is pretty simple.  Take a look at the following diagram, which illustrates the components used in the tutorial.

read more...

comments

FlashPunk, DAME and Lua Tutorial (Part 4)

04/16/2011

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 you haven't already downloaded the project files, grab them here.

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 DAME functions 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.

First of all, you will need to copy both of the Lua files in this project (FPDameTemplatesTutorial.lua and FPDameTemplatesTutorial_settings.lua) into the lua/Exporters folder within the DAME installation directory (mine was C:\Program Files\DAME\lua\Exporters).

The settings file (FPDameTemplatesTutorial_settings.lua) 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:

read more...

comments

FlashPunk, DAME and Lua Tutorial (Part 3)

01/27/2011

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 XML structure we'll be using:

<level>
	<tiles layer="template4" x="1440" y="0" width="480" height="480" tileWidth="32" tileHeight="32" widthInTiles="15" heightInTiles="15" >
		<tile tx="96" ty="0" x="0" y="0"/>
	</tiles>
	<sprites layer="template4">
		<sprite className="Balloon" x="1484" y="349" width="35" height="45" points="1" />
		<sprite className="Balloon" x="1621" y="2" width="35" height="45" points="1" spawnShape="74A916C5-C96B-62BE-6540-024B6D1237CB" spawnAmount="2" color="0x00ff00" />
		<sprite className="Balloon" x="1818" y="73" width="35" height="45" points="1" />
		<sprite className="Balloon" x="1750" y="343" width="35" height="45" points="1" spawnShape="74A916C5-C96B-62BE-6540-024B6D1237CB" spawnAmount="5" />
		<sprite className="FlyingPig" x="1843" y="1" width="60" height="51" spawnShape="5E3E76E3-431E-E1E1-B26C-930B32DB8AB1" spawnAmount="5" />
		<sprite className="Balloon" x="1629" y="346" width="35" height="45" points="1" />
	</sprites>
	<shapes layer="template1">
		<shape type="rectangle" x="1663" y="286" width="191" height="159" guid="74A916C5-C96B-62BE-6540-024B6D1237CB" />
		<shape type="rectangle" x="1659" y="64" width="257" height="160" guid="5E3E76E3-431E-E1E1-B26C-930B32DB8AB1" />
	</shapes>
</level>

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 level.  This could be called anything, usually it's just <xml> but in this case I went with something that made sense to me. read more...

comments

FlashPunk, DAME and Lua Tutorial (Part 2)

01/22/2011

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 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.

read more...

comments

FlashPunk, DAME and Lua Tutorial (Part 1)

01/18/2011

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 using FlashDevelop, 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 this tutorial (here's a link to an archive full of tutorials, since they have been taken offline: http://dl.dropbox.com/u/1526979/MattHubfolioArticles_HTML.zip).  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 this tutorial, and this book.  And just for a quick peak at what we will be creating, here is a screenshot:

read more...

comments

FlashPunk, DAME and Lua Tutorial (Part 0)

01/17/2011

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 creating a level with Flixel and  DAME.  Unfortunately, the tutorial ended before it actually got into Flixel, but I really fell in love with this app called the DAME Editor.  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.

Well, that was the short version.  For the long version, please read on: read more...

comments

Tom-as3-gotchi (Flash Game Tutorial) Part 4

06/11/2010

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 in the Flash IDE, I recreated the sketches in vector format, and then separated them into MovieClips and Graphic symbols.

read more...

comments

SlotMas3chine (Slot Machine AS3 Tutorial)

05/27/2010

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.  So in this example, once 2 of the reels in the slot machine match, those will not respond to the spin() 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.

here it is in action on wonderfl

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. read more...

comments

Tom-as3-gotchi (Flash Game Tutorial) Part 3

05/21/2010

If you haven't been following along, make sure to check out part 1 and part 2 of this tutorial first.  In the third part of this tutorial, I will cover the whole concept of getter/setter functions, along with the benefits of doing so, instead of using public variables.  A new class will be created too, Food.as.  Keep in mind that any or all of this code can change, move around or get scrapped completely, since this is somewhat of an "organic" tutorial.

To get started, let's have a look at what's changed in the Tom.as class. First, look at the getter function:

public function get weight():Number {
	// when returning weight, round to 1 decimal
	// this way "weight" getter function will return 201.5
	// while private variable _weight will still be accurate
	return Math.round(_weight * 10) / 10;
}

read more...

comments

Tom-as3-gotchi (Flash Game Tutorial) Part 2

05/20/2010

Continuing with our game from part 1, we will now start adding some code to our 2 classes, Tom.as and TomAS3Gotchi.as.  When we left off, the Tom class was basically an empty shell to store various information (health, food, hunger, boredom, etc.) and it had a simple constructor function (when a new Tom class is created, it traces "Hello, I'm Tom!").

Logically, when a new Tom is created, he should have default values set (for example, weight, height, mood and more).  As the project gets bigger and more complex, I may create a class just to store default values, but for now we'll just add them all to the top of Tom.as.  There are 3 main changes: read more...

comments

Tom-as3-gotchi (Flash Game Tutorial) Part 1

05/19/2010

Welcome to my first tutorial of many.  As I mentioned in an earlier post, I believe game programming to be a great way of learning any language, since it can force you to think a little more than a simple form-based application.  For this series, I want to create a variation of the traditional Tamagotchi virtual pet, which will allow me to cover a few different topics and programs in the process.  I've playfully named this a "Tom-as3-gotchi," which should be obvious to most (for the rest, consider it a free riddle).

Game Concept

Before writing a single line of code, I want to have a solid concept to design my game around.  The Tamagotchi page on Wikipedia, which was surprisingly sparse on information, states the core functions.  I'll be using those as a reference, specifically the functions for:

I've omitted the ability to connect with friends for now, but may decide to introduce that later down the line. read more...

comments

Hello World

05/18/2010

I won't bore you with the Wikipedia entry on "Hello World," which is pretty dry anyways (even for Wikipedia).  For just about every programmer on the face of the planet, Hello World represents their first approach to a new language.  For me, blogging is sort of a new language, along with writing tutorials.  I've constantly follow lots of flash blogs, including TheFlashBlog, tink, ByteArray, Bit-101, AnttiKupila, Kevin Hoyt, Actionscript 3.0 Design Patterns, Emanuele Feronato, Lost in Actionscript, Seb Lee-Delisle, Jesse Warden, and plenty others that I will list as time goes on.  I can also attribute most of my learning to following tutorials, although I haven't written many yet.

My goal is to write something new everyday, although realistically I'll manage about 3-4 posts per week.  Hopefully someone out there will get some use to these tutorials - but in line with one of my personal mantras (experience - expectation = happiness), I'll be writing for my own personal benefit at first... and if others can learn from this as well, all the better.

That being said, you can see the tutorials section here.

At work (IDEAS in Orlando, FL) I've been introducing my coworkers/friends to AS3, and recently figured out that the best way to teach, is through practical example.  I guess I should have just started with the obvious!  After reviewing a few other websites that teach Flash Programming, I've been inspired by the good and the bad.  Lee Brimelow's gotoAndLearn was inspiring in that I've personally watched it start from a simple tutorial site, into the Flash Blog of an Adobe Platform Evangelist.  I was also inspired by some very popular, but not-so-impressive sites, which got me thinking, "if they are teaching flash successfully to thousands, with ugly code..."

I also believe game programming is a good way of learning - since it often involves lots of different moving parts.  I'll leave my philosophy on game design to another post, but the tl;dr version is that before programming a game, the concept and gameplay should be fleshed out in detail, without any regards to technology.  Meaning, the concept of the game should be fun and exciting even if it were text-based, or a board-game, or a first-person shooter, and so on.  Of course, not all games are created this way, but it's how I like to approach them, as opposed to finding some game-engine and just working on the gameplay and fun as you code.

So... while you may not have learned anything yet, I promise to give it my best shot!  If you ever have any comments, questions or suggestions for new topics, please comment!  And of course, check out the tutorial section!

comments