Archive for the 'APE Tutorials' Category

APE Tutorial/Example 2 - Flash Physics Engine: Adding walls and multiple collisions

March 13th, 2008 | Category: APE Tutorials, Physics, AS3, CS3

DOWNLOAD SOURCE

This example just builds off the last example but I was just having a little more fun. I added a few more walls and dynamically added wheels to the APEngine to see multiple wheel collisions. I also modified the default elasticity property of the wheel to make the collisions more bouncy. I know it’s not a whole lot different from the last one but is it an example of progression and elaboration. Once again you can plug in the code below on the first frame of a timeline and it should work as long as you are linked to the APE source files.// Imports
import org.cove.ape.*;
import flash.events.Event;
import flash.display.MovieClip// listeners
addEventListener(Event.ENTER_FRAME, run);// Create an instance of the APEngine.
APEngine.init(1/3);
APEngine.container = this;
APEngine.addForce(new VectorForce(false,0,2));

// Create group
var group1:Group = new Group();
group1.collideInternal = true;

// Create rectangle to serve as the floor.
var rect1:RectangleParticle = new RectangleParticle(280, 350, 130, 10, 0, true) // Bottom Right
var rect2:RectangleParticle = new RectangleParticle(120, 350, 130, 10, 0, true) // Bottom Left
var rect3:RectangleParticle = new RectangleParticle(60, 200, 10, 300, 0, true) // Left
var rect4:RectangleParticle = new RectangleParticle(340, 200, 10, 300, 0, true) // Right

// Add to group
group1.addParticle(rect1);
group1.addParticle(rect2);
group1.addParticle(rect3);
group1.addParticle(rect4);

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

// Add button
mcStart.addEventListener(MouseEvent.CLICK, mcStart_CLICK);
mcStart.buttonMode = true
function mcStart_CLICK(e:MouseEvent = null):void
{
var wheel:WheelParticle = new WheelParticle(50, 0, 10);
wheel.elasticity = .6
wheel.addForce(new VectorForce(false,100,0))
group1.addParticle(wheel);
}
mcStart_CLICK()

1 comment

APE Tutorial 1 - Flash Physics Engine: Getting started

March 05th, 2008 | Category: APE Tutorials, Physics, AS3

DOWNLOAD SOURCE


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