Curso AS3

APE Actionscript Physics Engine

Estou testando algumas engines physics para Flash/ Flex. A engine APE do Alec Cove eu já conhecia, é simples e funciona bem, porém ainda está na versão 0.45a e possui poucos métodos/propriedades além do projeto estar parado há um bom tempo.

O APE foi escrito em Actionscript 3, mas para quem trabalha com AS2, a versão antiga do APE em AS2 é o Flade.

Abaixo segue um exemplo bem simples do APE, coloquei um botão para mudar a força da massa, porém a API ainda não possui um método para isto, improvisei reaplicando valores, mas não ficou legal.

PS. o APE não suporta ser exportado para Flash Player 10, existem conflitos entre objetos Vector.

package
{
	import flash.events.*;
	import flash.display.*;
	import org.cove.ape.*;
 
	public class baseAPE extends Sprite
	{
		private var myGrp:Group;
		private var n:uint = 1;
 
		public function baseAPE():void
		{
			stage.addEventListener(MouseEvent.MOUSE_DOWN, mDown);
			btn.addEventListener(MouseEvent.CLICK, mClik);
 
			this.initAPE();
			this.mClik(null);
		}
 
		private function initAPE():void
		{
			var largFloor:Number = (stage.stageWidth - 50);
 
			APEngine.init(1/3);
			APEngine.container = this;
 
			myGrp = new Group();
			myGrp.collideInternal = true;
 
			myGrp.addParticle(new RectangleParticle(100, 200, 150, 2, 0.3, true));
			myGrp.addParticle(new RectangleParticle(380, 150, 200, 2, -0.3, true));
			myGrp.addParticle(new RectangleParticle((largFloor * .5) + 25, stage.stageHeight - 20, largFloor, 6, 0, true));
			myGrp.addParticle(new RectangleParticle((largFloor * .5) + 25, 20, largFloor, 6, 0, true));
 
			APEngine.addGroup(myGrp);
 
			addEventListener(Event.ENTER_FRAME, onLoop);
		}
 
		private function mDown(evt:MouseEvent):void
		{
			if(btn.hitTestPoint(mouseX, mouseY)) return;
 
			var ball:CircleParticle = new CircleParticle(mouseX, mouseY, Math.random() * 20 + 10);
			ball.setFill(Math.random() * 0xFFFFFF);
			ball.setLine(0, 0, 0);
			myGrp.addParticle(ball);
		}
 
		private function mClik(evt:MouseEvent):void
		{
			var b:Boolean = btn.label == "Negative";
			btn.label = b ? "Positive" : "Negative";
 
			if(b) APEngine.addMasslessForce(new Vector(0 , n * -5)); else APEngine.addMasslessForce(new Vector(0 , n * 5));
 
			n = n + 1;
		}
 
		private function onLoop(evt:Event):void
		{
			APEngine.step();
			APEngine.paint();
		}
	}
}

This movie requires Flash Player 8.

6 Responses to “APE Actionscript Physics Engine”

  1. Thiago Coelho Says:

    bom post, uso bastante a APE em meus projetos. Fiz os testes com APE e BOX2D.

  2. Erick Souza Says:

    Legal Thiago, qual deles você tem trabalhado agora?

  3. Bruno Mikoski Says:

    Sem duvidas a Box2D é melhor de longe, ela tem muito mais funcionalidades, suporta objetos compostos, não só primitivos, alem de ser mais organizada e robusta.

    O contra é, ela é portada do C, então trabalhar em metros é bem chato no começo, e também as classes que não tem um padrão muito comum ao flahs, mais é realmente muito melhor que a APE!

    Estou no aguardo da Motor2, que vai ser o porte real da Box2D para o as3!

  4. Erick Souza Says:

    Oi Bruno, o Motor2 já está disponível: http://code.google.com/p/motor2/

  5. Boainfo Says:

    Boainfo…

    [...]APE Actionscript Physics Engine - Erick Souza[...]…

  6. Sismstoff Says:

    No situation what sort of outside undertaking you are committed in all over the winter, these coat will hold you snug and warm.Less than the particular artistic regarding skinheads which extremism, Donkey Jumper into your well known outfit market.”Rubaud simply no choice nevertheless to convey which. north face sale “Lasting character? “There are a couple of styles are generally painted, several are simply some cozy compared to the typical lower jacket.Remember that this helpful colour, typically wild coloration, so that you must rush to acquire manboobs to fit your shoes or boots, boots and even your own pocket book.Maybe,it truly is uncomplicated to ascertain how an ideal give you adore virtually North deal with with Jackets.

Leave a Reply