Question

I'm trying to create a simple disappearing action when a WheelParticle hits a special disappearing CircleParticle. Normally the WheelPartical bounces off of a bunch of other CircleParticles, but when the WheelParitcal collides with this CircleParticle, the action Pauses, an animation plays, and when the action resumes, many surrounding circle particles have dissappeared.

The problem is that the WheelParticle needs to just drop from a complete stop, but it continues as if having just bounced off of the, now non-existant CircleParticle. I'm having trouble clearing out the forces. I've tried init(), addForce() and changing .velocity amoung other things, but it keeps wanting to continue the lateral bouncing movement.

I'm using the latest trunk version of APE in order to capture Collision events for sound.

package{

import flash.display.MovieClip;
import flash.events.*;  
    import org.cove.ape.*;

public class DropTest extends MovieClip {

    public var self;
    public function DropTest(){
        self = this;

        APEngine.init(0.25);
        APEngine.container = this;
        //APEngine.damping = 0.92;
        APEngine.addForce(new VectorForce(false,0,15));

         var defaultGroup = new Group();
         defaultGroup.collideInternal = true;

         var peg1 = new CircleParticle(10, 30, 5, true, 0.2, 0.3);
         defaultGroup.addParticle(peg1);

          var peg2 = new CircleParticle(35, 30, 5, true, 0.2, 0.3);
         defaultGroup.addParticle(peg2);


         APEngine.addGroup(defaultGroup);           

         peg2.addEventListener(CollisionEvent.COLLIDE, function(evt:CollisionEvent){
                self.removeEventListener(Event.ENTER_FRAME, runAPE);    

                defaultGroup.removeParticle(peg2);
/*  The Wheel needs to stop and drop straight down from here.
                This doesn't seem to work.*/
                wheel.init();

                self.addEventListener(Event.ENTER_FRAME, runAPE);   
         });

        var wheel = new WheelParticle(12, 0, 10, false, 3);
        defaultGroup.addParticle(wheel);

        this.addEventListener(Event.ENTER_FRAME, runAPE);   

    }

    private function runAPE(evt:Event):void {
         APEngine.step();
         APEngine.paint();
      }
}
}
Was it helpful?

Solution

I think have a solution. I just re-instantiated the WheelParticle

peg2.addEventListener(CollisionEvent.COLLIDE, function(evt:CollisionEvent){
            self.removeEventListener(Event.ENTER_FRAME, runAPE);    

            defaultGroup.removeParticle(peg2);
/*  The Wheel needs to stop and drop straight down from here.
            This doesn't seem to work.*/

           //  Replace with this
            defaultGroup.removeParticle(wheel);
            wheel = new WheelParticle(wheel.px,  wheel.px, 10, false, 3);
            defaultGroup.addParticle(wheel);


            self.addEventListener(Event.ENTER_FRAME, runAPE);   
 });

The only problem now is that the rotation of the wheel changes when you re-instantiate it.

Is there a way to manually change the rotation?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top