Physics for Flash AS3

September 18th, 2008

I’ve been playing a bunch with physics engines for the last few weeks.  Physics engines basically serve to give your Flash Sprites some mass and body.  Your physics world can update your graphics so they can bounce off each other, bounce off walls, fall to the forces of gravity, and succumb to other forces all in a semi-realistic manner.

My exploration first took me from Papervision3D to WOWEngine.  Papervision3D is, of course, the popular realtime 3D engine for Flash.  It doesn’t have anything to do with phyics - but WOWEngine seems to be the hot dicussion for bringing physics into your 3D world.

WOW works like this….

Imagine a 3D world that you never see.  Yep, thats it.  That’s what the WOW does.  It’s the 3D world that never gets visualized in anyway.  Of course, the 3D world in question has complete information about all objects in the world and how they interact with their surroundings and forces surrounding them.

It’s actually a nice little setup - you get to keep your Papervision3D or regular 2D world seperate from your physics world.  So you have 2 different worlds - each operating independently of each other.  The way you tie them together is with a single handler ENTER_FRAME handler where you cycle through all the physics bodies and update your display with the proper x, y, z, or rotational properties.  The 2 worlds make it easy because you could use any 3D engine, 2D engine, or whatever engine you want - and you tie them together - there’s no dependencies, no skinning, no nothing - so it’s pretty handy, and a quick concept to grasp.  2 worlds - gotcha!

The problem is that the WOWEngine isn’t that great of a physics engine (yet!).  Another unfortunate problem is that its the only Actionscript Physics engine that handles 3D.  So if you use 3D, you’re kind of stuck using this or writing your own.

WOWEngine is based off of another engine called APE (Actionscript Physics Engine).  APE is a 2D physics engine that seems to actually be pretty good.  The problem with WOW, is that it has such potential, and works pretty well, but hasn’t implemented the richer features of APE yet.  The author definitely plans to, it’s on the roadmap, but we’re impatient we need it now!

The killer feature that makes a great physics engine in my opinion, is Rigid Body Dynamics - which APE has and WOW lacks.  To explain rigid body dynamics a little bit, let me tell you a little bit about my initial experimentation.

My big “hello world” application was basically making a few balls drop from the sky and hit the ground.  I initially tested in 2D, and just ignored the Z axis.  So we’re talking normal Flash Sprites here.  So the balls hit the ground, bounced off of each other, all pretty cool - and what you’d expect from a physics engine.

Next I tried the same thing with squares.  Still cool, but not quite right.  That’s because I still had to treat each square as a generic ball particle.  With no Rigid Body Dynamics - I couldn’t build a little fortress with my cubes!  That’s because without being able to define a polygon or even a cube, whatever graphics you have…..just sort of act like balls and slide off each other.

So that’s the my big problem.  Someday WOW will be awesome, but not yet for my purposes.

Next I checked out Foam.  Foam is a 2D Physics engine for Actionscript 3.  Foam is actually pretty sweet!  I didn’t spend long on it, though.  The reason is that after I experimented with WOW, I didn’t really like how Foam worked.  It seemed to handle Physics well - but it seemed to integrate the graphics and physics world too much for me.  I think I preferred them seperate!  I didn’t get far into Foam, but it seemed more like that Foam would take over your stage and you’d skin the physical bodies.  Before I went into this physics thing, it’s how I expected things to work - but I just couldn’t dig in after playing with WOW.

So again I moved on…

Finally I hit Box2DAS3.  This is the one I settled on - it has it’s problems, but if you can overcome it, then I do think it’s the best.  Box2DAS3  is a Actionscript 3 port of Box 2D.  Box 2D is an opensource physics package for C++.  In fact, Box2D has evolved to become Bullet - a 3D version of the physics engine.  Hopefully we’ll see Bullet 3D someday soon.

Box2DAS3 supports all the great features a good physics engine should….well OK OK, I’m not an expert - it supports all the great features I *think* a good physics engine should.  It also follows my beloved 2 worlds philosophy that I liked from WOW/APE.  For me it’s perfect….

….well almost perfect.  I think it has one flaw.  The flaw is that it’s a C++ port, and not really specific to Flash.  If I went back in time and warned myself of this, I would’ve been pretty dismissive and said “So what?  Code is code!”.

Well first of all it seems like classes have the bare minimum of comments - so you just kind of get the picture what everything does.  And it’s really not clear what each class or package does - unless you know….um…how to write a physics engine.  So it’s a little bit of a catch-22.  Like a simple body is name b2Body.  To create a body you need to create a shape definition (b2ShapeDef), convert that to a shape, and then convert the shape to a body, and then add the body to the world.  And it seems there’s only one way to add a body to a world, and that’s through a reference to the world, even though when you create a body from scratch, there’s a world parameter - but it doesn’t seem to work.  Well, I’m rambling.  Needless to say it’s confusing for a newbie - and on top of that there are things like manifolds and AABB - all things I don’t understand but there to get in the way and hamper learning.

But, if you study the examples they give you - you start to get a feel for how things work.  And once I did that - I stumbled a little, especially on design patterns - but got things working pretty well.  My design pattern quandry was that the framework was very incompatible with an inheritance based design - it was like really rubbing things the wrong way when I tried to use inheritance in my design.  What you really need to realize, is that a Factory type of design pattern works much better.

I ended up creating a base class like you would in Papervision3D.  The base class extends the stage and creates a common physics world setup as part of that stage.  Your main class would inherit this “physical stage” and contain the main stuff you want to program (hopefully keeping references to b2bodies and b2worlds to minumum, just cause it’s hard to understand!).

On the side - I have a physical object factory static class.  Here’s I’d call createPhysicalBall or something like that, and poof it’d create me a ball….passing back seperate references for the graphics and the phyiscal body.

So that’s how I roll with the physics.  It adds some great realism to the boring old games.

Visual Ambiance in Music Games

September 14th, 2008

So it would appear that visual ambiance in music games can be pretty important.  Take most rhythm games…

Background colors change, flashes appear, etc, all in time to the music in games like Guitar Hero and Rockband.  In PaRappa, characters dance and jerk their bodies in time.  What you end up getting is more music video like.

Rhythm games, those games where you have to tap your fingers, feet, or guitar to the beat as part of gameplay can feel more music video like because you end up “playing” the music to some effect.

Reactive games on the other hand, may have to rely on visual ambiance more.  Reactive games, are more often than not, played like any normal game.  The environment in the game may react to music, but you don’t.  So if you’re not required to react to the music, the music can start to take a back seat to the game play, and it starts feeling less choreographed.

This is why visual ambiance can become more important, and probably should be in your face more in a reactive game.  It would seem that when you don’t control the choreography of the game, other musical visuals need to step up to help out and make the game FEEL musical.

I used the example before of AudioSurf (published by Valve).  I crticized it for not tying the visual to the music as well as it could have.  I can’t criticize it for attempting ambiance to tie the music into the game better, because it does an adequate job of this with colors and background visuals.  However, the environmental reactions to the beats still seem too out of touch with the music, and the ambiance is all it has going for it to make it feel choreographed.

So, the closer you can tie in your reactive environmentals the better.  But like I said, even that might not be enough, as your game starts focusing on the goals of the game - which is why visual ambiance becomes a VERY important silent partner.

Lame comic attempt after watching the RNC

September 2nd, 2008

No its probably not very funny - but I got bored with code tonight and the RNC was on with Fred Thompson talking about how McCain POW camp stay….Terror Cats - Vs - McCain

Music Video Games - The Official Website

August 21st, 2008

OK, I will be very interested to see how this plays out.  The site is Music Video Games.  I’m so curious in fact, that I’m analyzing and critiquing the SMALL amount of website they have up.

So, what I gather from press releases, is that Music Video Games will be a portal to deliver casual games with beat matching to popular songs (record label Rhino is getting involved).

Kind of cool, not quite the angle I’m thinking I’d like to go, but pretty dern close.   Like I said, it’s one to watch once it gets going, but right now I don’t have much to go on other than….

1.  Its lame logo… whats up with that?  If that’s the extent of the design skills, I’m not sure if it’s gonna be anything special

2.  It’s name - OK the spin with MvG, and comparing it to MTV, not bad - but why not just call your company MvG, the logo designs itself practically!

3.  Patents - I don’t know what kind of “patented beat matching” technology they came up with, but I’ve put a lot of thought into finding beats, and if it’s anything beyond the obvious methods I’m employing in my experimentation, more power too them,  but if not, I’m going to be very depressed for the world if they land a patent.

4.  The plan - A casual gaming portal?  I’m not sure if they’ll land a wide audience if they take some games and add music without a bigger hook.    I mean, its pretty cool and all, but once launched and the novelty wears thin, I wonder if they’ll really have much to differentiate themselves from a normal site.  Yah, each game will have lots of replay value due to songs they could mix and match if they’re smart - so we’ll see.  This is not really a criticism but curiosity I guess.

So, will this be successful?  Will we see innovative games?  Or will we see a bunch of rhythm games or guitar hero clones with an impressive music library on one site.

Only time will tell, I wish I wasn’t teased with the crappy splash page.  Oh well.

Reactive Music Games

August 7th, 2008

Well, I’ve been doing some research lately. Back in January I wrote up a a blog post titled “It’s been 10 years since PaRappa - now what?”. I was exploring the mainstream music games. Little did I know that these games are all part of the group known as “Rhythm” games. Of course, many folks know what a rhythm game is, and I do too.

What I DIDN’T know is that Rhythm games are just one of a handful of different types of music games. Rhythm games can include any games that play a soundtrack and must press buttons in time to the game. Examples include “Dance Dance Revolution”, “Guitar Hero”, “Rock Band”, and “PaRappa the Rapper”.

“Pitch” games recognize the pitch of your voice from a microphone, and like Rhythm games, you must keep time with the music, but instead using the pitch of your voice to sing along. “Karaoke Revolution”is one note-able example. “Volume” games include games like “Mad Maestro” and the upcoming “Wii Music”. In these games you can control the volume of the music in the game through various means, thereby influencing the game play.

Next are “Eidetic” music games. These games will play a musical sequence, and it’s up to the player to repeat the sequence back. In this regard, “Simon” is the oldest music game around.

To be short and sweet, I’ll lump “Free Form” and “Generative” music games together. In both of these game types, the player and the elements of the game come together to create a unique sound track. It seems that creativity is more likely in the “Free Form” music game.

The last genre, and the one I’m most interested in, is the “Reactive” genre. Here, a pre-composed soundtrack plays, and in game elements can react to the volume, frequency patterns, and beats in the music. All of these genres, with the exception of the Rhythm game, are hard to come up with examples for.

AudioSurf

That said, there are a handful of Reactive music games that I’m aware of. The first was published in February 2008 and created by an outfit called “Invisible Handlebar” and available from Valve software’s Steam game portal. In this game, called AudioSurf, you move a race car left and right over a racetrack. The goal is to collect blocks that appear on the road, and stack them in groups of 3 to get points. You load in your own MP3, and the background environment animates in time with the music. The track itself dips and rises in time with the music as well. Supposedly, the blocks you collect also appear in time with the music as well - however they appear on the road far in advance and far in the distance of when you collect them. As a result the gameplay doesn’t really feel in synch with the soundtrack. It’s only if you really pay attention to your surroundings, and not to the game play to really get that connection. For example, a hip-hop track by “Jurassic 5″ is a little more bouncy than a rock track by “Living Colour”, but it can get hard to tell in gameplay the difference between the songs.

There are a few Adobe Flash examples of this like “Rhythm Night”, but the game play isn’t all that great. Most of the Flash examples to date are either Rhythm games, Eidetic, or just general music lesson games.

Pteranodon

Fortunately there is an excellent example to draw from - and that’s “Pteranodon” by an independent game developer from Sweden known as Nifflas. His name is Nicklas Nygren, and “Pteranodon” is a classic side-scrolling space shoot-em up game. The twist of course, is that the enemies appear on screen and fire at your in time with the music. Its a pretty simple game by today’s standards - though the connection between what’s on screen and the timing of the music makes me giddy. Apparently he composes his own music, so it’s no surprise that “Pteranodon” just features one track, but one can just imagine where you can go from there.

A Codie Award to add to my resume!

May 26th, 2008

The 2008 Codie Awards have been announced.  Little did I know that a project I played a major part in was at least nominated for a couple Codies, we actually WON the award for “Best Instructional Solution for Students at Home”.  Pretty nifty, and its just the latest in a series of awards for the Pokemon Learning League.

So far the awards have been the Codie, a 2007 Outstanding Products Award from iParenting, a 2007 Best Educational Software Award, and we were a finalist for Distinguished Achievement from the Association of Educational Publishers.

I won’t go into the “making of” in the least, cause you know, it’s safe to assume that most clients don’t appreciate any ups and downs of working with them made available in a public forum.  But…..pretty nifty anyway right?

The project is:
http://www.pokemonlearningleague.com/

And of course, yes I played a good part in it, but there were plenty more people involved at the company I work for 360KID.

Blogged with the Flock Browser

Budget Hero

May 20th, 2008

We just launched a new application at 360KID!  I wish I could say I did all of it, or even most of it, but I did step in to help a lot during the final stages - just so I can say I took all the credit from the project’s real programmer Clint Little.  I have a few Flex projects under my belt now, and they all look fantastic compared to most of the ones I’ve seen out there.  This one is no exception thanks to the great animation and illustration my company does.  I look forward to launching more and more Flex applications that have a fun look and feel.  We’re so close to launching our other projects, I’d love to show them since I was the main developer - but this one is another one to be proud of regardless of who did it.

This game called Budget Hero was developed for American Public Media, and allows you to play cards to adjust the federal budget and see if you can balance it.   Also allowing you to earn badges, you can see if you’re also doing your part to maintain the military, health care, etc.  It’s up to you to make sure the stuff you think is important doesn’t wither away and STILL maintain the budget.

Click to Play Budget Hero

The Chuckles!

May 20th, 2008

Still waiting on the final video, but this is part of my March Madness of projects. My year has been insane so far with way to much work. Like an idiot, when my friend Jason Burke asked if I could help out with a series of 30 or so illustrations to be finished in less than a month, I said yes!

But, it was fun. I hadn’t done illustration work in a while, and had just discovered the gradient mesh tool in Illustrator. The tool allowed me to make some cartoonish, yet 3D like drawings. Yes, I’m a perfectionist, so some didn’t come out as good as I’d like, but I’m happy with it overall.

First, I’ll show the one that creeped out my wife the most. This is the forced child clothing labor camp:

On the next drawing I learned to use the pattern brush in Illustrator a little better than my previous attempts at it.  It was incredibly useful for painting the leaves on in various configurations, and the grass as well.  And there’s tons more - but lots were small, here’s the rest I put in my portfolio:

Thats it!  I haven’t blogged since February, but I do have more projects coming down the line - they just need to launch.  I have worked hard this year, it’ll be nice when I have something to show for it.

Does Illustrator CS3 Render a Buggy SWF?

January 15th, 2008

I ‘ve been working with Flex 3 for a little while now, and started my first commercial Flex project in December. Luckily I got the CS3 Master Suite…whoo! So since it’s more fun to draw in Illustrator, that’s what I’ve been doing. In fact, on this latest project I’ve been doing, I’ve been having our artists deliver Illustrator files, then I just export SWF asset libraries. I take these files and embed them right into Flex! It’s pretty nifty, and I’ve been loving the workflow.

Well, the project is going full steam, and I’ve got a bug on my plate. I have some scrolling lists full of graphics. These lists are styled with a background image using 9 Slice Scaling. At first glance it’s fine, but I’ve been noticing some weird redraw issues in the project. It’s pretty subtle, but the bounding box of these scrolling images will discolor the background image. More specifically, if I have a colored square layered over another colored square as my Illustrator artwork, the bug will take away parts of the square in the forefront revealing whats behind it.

I tried so many different export options, and nothing worked! Finally I copied and pasted this same art into Flash CS3 to produce the same SWF asset library, and guess what? No problems.

There must be some buggy SWF producing code in Illustrator CS3. I hope I’m doing something wrong, but I can’t imagine what. But I guess I’ll use Flash when stuff breaks on me, oh well…..the Illustrator high was fun while it lasted.

To see what I mean, check out this Flex Application. The Flash list on the left scrolls fine, but check out the Illustrator list. If you scroll and look at the bottom, you can see the redraw issue.

Christmas in Vegas

January 6th, 2008

Check ot our Vegas Photos here…

We’ve been back from our nice Christmas trip to Las Vegas for around a week now, and I just posted our photos on my website. Becca and I arrived on Christmas morning, and the nice receptionist at our hotel let us check in at 11, which I great, cause we didn’t feel like lugging our bags around for another hour. We got the top floor, you can see our nice view here.

Of course we were a little tired coming in - we took the red eye leaving at 3am or so. So, we had a relaxing Christmas after we checked in. We promptly hit the hot tub and ordered a couple of Bloody Mary’s.

Speaking of the hot tub, it was right next to the pool of course - which was surrounded by a shark tank! On our last day there we took the elevator up to the 3rd floor to take the water slide which passed straight through the tank.

Becca’s sister Christa came to join us on the 26th - and we wandered all over the city visiting the new Wynn and a few other hotels.

And yes, there was gambling. We probably blew $100 on those video blackjack and roulette machines. Not so good. Christa and I also blew $60 or so when we hit the blackjack tables oh well.

While I was feeling discouraged, I think she won some of that money back. The next day though when Christa was gone - team Gomez Farrell hit the tables. Becca armed with $60 and I with $20. We each walked away earning over $120 from the Blackjack and Roulette tables. Becca hit the jackpot on some penny slots as she put in a dollar and came out with $20. So all in all, we came out pretty even - though it was pretty fun to win all that cash in the end.

And of course we both came down with stomach bugs that took us a week to get over. I think we’re done with Vegas for now. Maybe we’ll take advantage of our passports next trip.