Swami Charan's Blog My personal blog…

8Dec/090

Making particles dragable in APE

As you all know what APE is, I will go directly into what problem i faced when started with it and how i overcame it. First of all, APE source has class named Vector defined in it. When we try to publish any content with APE on Flash CS4/FP 10, there will be a conflict that arises between Vector class of APE and Vector Datatype of Flash Player 10.

So, i had to modify the APE source to rename the Vector class in APE and change the reference of Vector in APE source with the new name. Then i could able to run content with APE on Flash Player 10. You can download the modified source from here.

Making Particle Dragable:

After successful in running the content on Flash Player 10, i wanted to check out how drag works on APE particles. There are separate class files called 'DragableCircleParticle.as' and 'DragableRectangleParticle.as' under Files section of APE Google Group.

Place these .as files under 'source\org\cove\ape' Folder of APE.

Using these classes can make our work easy in making particles dragable.

These dragable particles can be initialized as follows:

DragableCircleParticel(x:Number, y:Number, radius:Number, fixed:Boolean, mass:Number,elasticity:Number, frictio:Number);

DragableRectanlgeParticle(x:Number, y:Number, width:Number, height:Number, rotation:Number, fixed:Boolean, mass:Number, elasticity:Number, friction:Number)

Here is the sample code to make use of these classes:

 

stage.frameRate=60;
import org.cove.ape.*;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.Event;

addEventListener(Event.ENTER_FRAME, run);

var apeholder:MovieClip = new MovieClip();
apeholder.graphics.drawRect(0, 0, 550, 400);
addChild(apeholder);

APEngine.init(1/3);
APEngine.container=apeholder;

APEngine.addForce(new VectorForce(false,0,2));
var examplelevel:Group = new Group();
examplelevel.collideInternal=true;

var leftwall:RectangleParticle=new RectangleParticle(5,200,10,600,0,true);
leftwall.setStyle(3, 0x000000, 1, 0xFFFFFF,1);
examplelevel.addParticle(leftwall);

var rightwall:RectangleParticle=new RectangleParticle(545,200,10,600,0,true);
rightwall.setStyle(3, 0x000000, 1, 0xFFFFFF,1);
examplelevel.addParticle(rightwall);

var bottomwall:RectangleParticle=new RectangleParticle(275,395,550,10,0,true);
bottomwall.setStyle(3, 0x000000, 1, 0xFFFFFF,1);
examplelevel.addParticle(bottomwall);

var block:DragableRectangleParticle=new DragableRectangleParticle(Math.random()*550,- Math.random()*50, 80, 80,0, false,3);
examplelevel.addParticle(block);

var wheel:DragableCircleParticle=new DragableCircleParticle(Math.random()*550,- Math.random()*50, 20, false,3);
examplelevel.addParticle(wheel);

APEngine.addGroup(examplelevel);

function run(event:Event):void {
	APEngine.step();
	APEngine.paint();
}

Here is the output SWF.

Hope this would be helpful...

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.