Mar 5
APE Tutorial 1 - Flash Physics Engine: Getting started
I have searched for days now looking for good APE tutorials and I have found little to no help. I decided to gather what I know, digest it for the average human being and post tutorials. I will try to make this concise.
For this first tutorial I have decided to strip down using APE to it’s basic necessities; present a good foundation that can be easily built off of. The following is the sequence of what needs to happen to get a firm understanding of how APE is used.
- Import the APE package
- Create an instance of the engine
- Create a group that you will add particles to (wheels, circles, rectangles, etc)
- Create your particles
- Add your particles to the group
- Add the group to the engine
- Run the engine
Thats it, once you grasp this concept you are on your way to leading the industry with richer internet applications and you can promise the world a better tomorrow. I suggest going thru the APE documentation to see what you can add on to my file. I will do more Tutorials soon where I will go more in depth on how to use the bells and whistles. Below is the code I used to make the example. You can actually plug this code into the root of the timeline with no graphics and it will work as long as you have APE hooked up to your Flash AS3 class path. Hit me up with questions.
// Imports
import org.cove.ape.*;
import flash.events.Event;
// listeners
addEventListener(Event.ENTER_FRAME, run);
// Create an instance of the APEngine.
APEngine.init(1/4);
APEngine.container = this;
APEngine.addForce(new VectorForce(false,0,2));
// Create group
var group1:Group = new Group();
group1.collideInternal = true;
// Create wheel with motion.
var wheel1:WheelParticle = new WheelParticle(0, 0, 30);
wheel1.addForce(new VectorForce(false,30,0))
// Create rectangle to serve as the floor.
var rect1:RectangleParticle = new RectangleParticle(200, 300, 300, 10, 0, true)
// Add particles to group.
group1.addParticle(wheel1);
group1.addParticle(rect1);
// Add group to engine.
APEngine.addGroup(group1);
// Constantly run these functions to keep the engine running.
function run(evt:Event):void {
APEngine.step();
APEngine.paint();
}
3 Comments so far
Leave a comment
Very nice tutorial. Easy to follow and informative. I was looking in the documentation of APE and was wondering what the difference between a collidable and a composite were. It didn’t seem to paint a clear picture for me. Any clues?
I was wondering the same thing myself last night. I was trying to read up on it but the documentation is kind of dry. Let me do a little more research on it and I will reply with what I find. Or if anyone else knows what it is, please elighten us here. I’ll be able to visit this within the next few nights. Thanks for the question.
awesome tutorial for someone looking to get his feet wet with APE…there’s very little, as you said, out there for learning APE besides the actual APE documentation…please keep the ape tutorials coming!