Esto es una prueba de la librería APE Physis, les posteo el código el cual fue tomado en principio por un ejemplo posteado y fue modificado por nosotros para ver el desempeño de la librería.
Codigo:
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- backgroundColor="#444444"
- creationComplete="initApp()" verticalAlign="top" horizontalAlign="left" >
- <mx:Script>
- <![CDATA[
- import flash.sampler.DeleteObjectSample;
- import org.cove.ape.AbstractCollection;
- import org.cove.ape.WheelParticle;
- import org.cove.ape.RectangleParticle;
- import org.cove.ape.AbstractParticle;
- import org.cove.ape.Group;
- import org.cove.ape.CircleParticle;
- import org.cove.ape.Vector;
- import org.cove.ape.APEngine;
- [Embed(source='/assets/testApeLogo.swf', symbol='renito')]
- [Bindable]
- public var imgCls:Class;
- private var contentHolder:Sprite=new Sprite();
- private var defaultGroup:Group=new Group();
- private var mousePosition:Point;
- private var myTimer:Timer;
- private function deleteObjects(e:TimerEvent):void
- {
- trace("TICK");
- var len:int = defaultGroup.getAll().length-1;
- var part:AbstractParticle;
- for(var i:int =len; i>=0;i--){
- trace((alto+100 < AbstractParticle(defaultGroup.getAll()[i]).position.y) + " "+(alto+100) +"<"+AbstractParticle(defaultGroup.getAll()[i]).position.y);
- if(alto+100 < AbstractParticle(defaultGroup.getAll()[i]).position.y)
- {
- part = defaultGroup.getAll()[i];
- defaultGroup.removeParticle(part);
- delete(part as Object);
- }
- }
- }
- private function refreshTimer(e:TimerEvent):void
- {
- trace("NEW TIMER");
- myTimer.removeEventListener(TimerEvent.TIMER,deleteObjects)
- myTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,refreshTimer);
- myTimer.stop();
- myTimer = null;
- myTimer = new Timer(10*1000,Number.MAX_VALUE);
- myTimer.addEventListener(TimerEvent.TIMER,deleteObjects);
- myTimer.addEventListener(TimerEvent.TIMER_COMPLETE,refreshTimer);
- myTimer.start();
- }
- private function initApp():void{
- myTimer = new Timer(10*1000,Number.MAX_VALUE);
- myTimer.addEventListener(TimerEvent.TIMER,deleteObjects);
- myTimer.addEventListener(TimerEvent.TIMER_COMPLETE,refreshTimer);
- myTimer.start();
- spriteWrapper.addChild(contentHolder);
- addEventListener(Event.ENTER_FRAME,run);
- APEngine.init(1/3);
- APEngine.container=contentHolder;
- APEngine.addMasslessForce(new Vector(0,9.8));
- defaultGroup.collideInternal=true;
- ground=new RectangleParticle(viewScreen.width/2,viewScreen.height-40,viewScreen.width-50,40,0,true);
- ground.setFill(0xCCCCCC);
- defaultGroup.addParticle(ground);
- APEngine.addGroup(defaultGroup);
- viewScreen.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
- ancho = viewScreen.width;
- alto= viewScreen.height;
- }
- private var ground:RectangleParticle;
- private var ancho:Number = 0;
- private var alto:Number = 0 ;
- private var hijos:int =0;
- private function run(e:Event):void{
- APEngine.step();
- APEngine.paint();
- if(hijos != defaultGroup.getAll().length){
- hijos = defaultGroup.getAll().length;
- trace(defaultGroup.getAll().length);
- }
- if(ancho != viewScreen.width || alto != viewScreen.height){
- defaultGroup.removeParticle(ground);
- ground=new RectangleParticle(viewScreen.width/2,viewScreen.height-40,viewScreen.width-50,40,0,true);
- ground.setFill(0xCCCCCC);
- defaultGroup.addParticle(ground);
- }
- }
- private function addSelectedParticle():void{
- var createdParticle:AbstractParticle;
- if(radiobutton1.selected)
- createdParticle=createCircle();
- if(radiobutton2.selected)
- createdParticle=createRectangle();
- if(radiobutton3.selected)
- createdParticle=createWheel();
- createdParticle.setFill(itemColor.selectedColor);
- defaultGroup.addParticle(createdParticle);
- }
- private function createCircle():AbstractParticle{
- var circle:CircleParticle=new CircleParticle(mousePosition.x,mousePosition.y,circleRadius.value,isFixed.selected,myMasa.value,elastico.value,roce.value);
- return circle;
- }
- private function createRectangle():AbstractParticle{
- var rectangle:RectangleParticle = new RectangleParticle(mousePosition.x,mousePosition.y,circleRadius.value*2,circleRadius.value*2,0,isFixed.selected,myMasa.value,elastico.value,roce.value);
- return rectangle;
- }
- private function createWheel():AbstractParticle{
- var wheel:WheelParticle = new WheelParticle(mousePosition.x,mousePosition.y,circleRadius.value,isFixed.selected,myMasa.value,elastico.value,roce.value,1);
- return wheel;
- }
- private function onMouseDown(e:MouseEvent):void
- {
- mousePosition=new Point(e.localX,e.localY);
- addSelectedParticle();
- }
- ]]>
- </mx:Script>
- <mx:HBox width="100%" height="100%" >
- <mx:VBox backgroundColor="0xEEEEEE" cornerRadius="5" borderStyle="solid" borderThickness="1">
- <mx:Form>
- <mx:FormItem label="Forma del Objeto">
- <mx:RadioButtonGroup id="particleGroup"/>
- <mx:RadioButton label="Circulo" id="radiobutton1" groupName="particleGroup" selected="true"/>
- <mx:RadioButton label="Cuadrado" id="radiobutton2" groupName="particleGroup" />
- <mx:RadioButton label="Rueda" id="radiobutton3" groupName="particleGroup"/>
- </mx:FormItem>
- <mx:FormItem label="Masa">
- <mx:NumericStepper minimum="1" maximum="100000" stepSize="1000" id="myMasa" value="1"/>
- </mx:FormItem>
- <mx:FormItem label="Radio/Ancho y Alto">
- <mx:NumericStepper minimum="1" maximum="100" stepSize="5" id="circleRadius" value="20"/>
- </mx:FormItem>
- <mx:FormItem label="Constante de Elasticidad">
- <mx:NumericStepper minimum="0" maximum="1" stepSize="0.01" id="elastico" value="0.3"/>
- </mx:FormItem>
- <mx:FormItem label="Constante de Roce">
- <mx:NumericStepper minimum="0" maximum="1" stepSize="0.01" id="roce" value="0.01"/>
- </mx:FormItem>
- <mx:FormItem label="Color del Relleno">
- <mx:ColorPicker id="itemColor" selectedColor="0xFF0000"/>
- </mx:FormItem>
- <mx:FormItem label="Afectado por la Fuerzas">
- <mx:CheckBox id="isFixed" fontStyle="normal" fontWeight="bold" fontSize="14"/>
- </mx:FormItem>
- </mx:Form>
- </mx:VBox>
- <mx:Canvas id="viewScreen" width="100%" height="100%" backgroundColor="#FFFFFF" backgroundAlpha=".3" borderStyle="solid" borderThickness="1" cornerRadius="5" verticalScrollPolicy="off" horizontalScrollPolicy="off">
- <mx:Image rotation="-45" alpha="1" x="{viewScreen.width/2}" y="{viewScreen.height/2}" source="{imgCls}" horizontalAlign="center" verticalAlign="middle" />
- <mx:UIComponent id="spriteWrapper" width="100%" height="100%"/>
- </mx:Canvas>
- </mx:HBox>
- </mx:Application>
Descargar Archivos:
No hay comentarios.:
Publicar un comentario