Hyphens are everywhere in our CSS world, and it's a pain. I can't double-click the class names to select them, I always have to hold shift+alt to grab the whole thing. Using shift+alt+left(or right) won't suffice, as hyphens stop selection each bit counts as a word !
This is about development time. Quick selections are crucial for fast development.
As I only adhere to conventions where I find them useful to humanity, I'm sticking to underscore_sweetness to make my editing much faster.
Don't get me started with the "|= attribute selector" because one single good feature is no justification for a permanent handicap while coding.
In this Box2dAs3 example I want to demonstrate the Multiplayer (hotseat) implementation of driving / steering a sort of ship / vehicle through an empty space.
In this example gravity is zero so the ships "float" in space.
Summary of classes:
CORE.as - the base for the whole thing, and the blur trail processing.
Main.as - construction of the Box2dAs3 World, walls and players.
Player.as - definition of players and keyboard control.
ContactListener.as - the place to deal with collision detection and reaction.
To spice it up I've added a blur trail effect to the players.
This example is a pointless game. But I must confess I had some fun playing "catch" with a friend of mine. If you catch your opponent, it's his time to hunt you.
Controls:
USE THE ARROW KEYS FOR PLAYER ONE AND the W.A.D. keys FOR PLAYER 2.
Ever wondered how to make those smooth looking blur trails with AS3? Well if you did and still don't know, you have just found it. I's done using BitmapDatas drawing a Bitmap with a given BlurFilter in a given Sprite or MovieClip which contains all the contents we want to have the motion blur. Some examples in the internet don't handle this properly because they flood the backgound with a colour, but in this one we are using a custom background to demonstrate how it is implemented. The trick is that the BitmapData must apply the "draw()" method only in a given Sprite or MovieClip where all the contents-to-be-blurred are nested.
The background pattern is a great technique developed by the guys at Bumpslide.
Here is an example of the fine Physics engine for Flash (AS3) named Box2DAS3.
This example demonstrates the implementation of some features required for real game or application development.
These are:
Collision detection (and reaction)
Mouse interaction (for all objects)
Keyboard interaction (for the main character - blue ball)
Camera follow (for the main character - blue ball)
Custom graphics (taken at run-time from the Flash library)
Collision detection (and reaction):
To implement collision detection and reaction, one must first initialize a ContactListener class and then modify it to have the collision reactions the way we need. The initial setup is pretty easy:
contact_listener_var = new ContactListener()
m_world.SetContactListener(contact_listener_var);
Check the source code to see how to reactions are handled.
Mouse Interaction:
Mouse interaction is easy to implement, one has only to activate it with the appropriate Box2DAS3 code, check the source for details.
Keyboard interaction:
The keyboard interaction had to be implemented manually, at least it was the fastest way I had to obtain the behaviour I required from the main character (the blue ball). To do this I used the great Key class from CASALIB check the source code for details.
Camera follow:
It basically consists in moving the Sprite where your Box2DAS3 "world" is nested. Pretty easy. I added a slight easing effect to make it smoother. NOTE: in this example it is disabled when the user clicks an object.
Custom Graphics:
Box2DAS3 objects have a body definition property (class b2BodyDef) which in it's turn has a sub property named "userData" that contains the visual content of your Box2DAS3 object. It's basically a MovieClip. So you may draw graphics in it or addChild a MovieClip from your Flash library into it. Like bodyDef.userData = new SymbolLinkageName();
Recent Comments