yarrasid
unread,Jul 12, 2008, 8:12:22 PM7/12/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to APE General
I'll admit that I am new to as3 so please excuse my ignorance.
I began using this fantastic engine recently, but unfortunately I
don't seem to be even capable of mastering the basics. My problem is
in removing particles from a group/simulation. I am currently using
the removeParticle() method, but it does not work consistently.
This is the entire code (changed very slightly from an example):
import org.cove.ape.*;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.display.Sprite;
// listeners
addEventListener(Event.ENTER_FRAME, TimeStep);
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, KeyReleased);
//Ape
// ape init
APEngine.init(1/4);
APEngine.container = this;
APEngine.addForce(new VectorForce(false,0,2));
var defaultGroup:Group = new Group();
defaultGroup.collideInternal = true;
var ground1:RectangleParticle = new
RectangleParticle(150,200,200,10,-0.1,true);
defaultGroup.addParticle(ground1);
var ground2:RectangleParticle = new
RectangleParticle(300,50,300,10,0,true);
defaultGroup.addParticle(ground2);
var ground3:RectangleParticle = new
RectangleParticle(120,55,30,30,0,true);
defaultGroup.addParticle(ground3);
var wheel1: WheelParticle = new WheelParticle(160,20,10,false,2);
defaultGroup.addParticle(wheel1);
var wheel2: WheelParticle = new WheelParticle(200,20,10,false,2);
defaultGroup.addParticle(wheel2);
var wheel4:SpringConstraint = new SpringConstraint(wheel1, wheel2,
0.5, true, 1);
defaultGroup.addConstraint(wheel4);
// styles and displays
ground1.setStyle(0, 0xFF0000, 1, 0xFF0000,0.5);
ground2.setStyle(0, 0xFF0000, 1, 0xFF0000,0.5);
ground3.setStyle(0, 0xFF0000, 1, 0xFF0000,0.5);
wheel2.setStyle(0, 0xFF0000, 1, 0xFF0000,0.5);
wheel1.setStyle(0, 0xFF0000, 1, 0xFF0000,0.5);
APEngine.addGroup(defaultGroup);
var win = false;
//
function KeyPressed(event:KeyboardEvent):void {
if (event.keyCode == Keyboard.UP) {
wheel1.angularVelocity = 0.5;
wheel2.angularVelocity = 0.5;
}
if (event.keyCode == Keyboard.DOWN) {
wheel1.angularVelocity =- 0.5;
wheel2.angularVelocity =- 0.5;
}
}
function KeyReleased(event:KeyboardEvent):void {
wheel1.angularVelocity = 0;
wheel2.angularVelocity = 0;
}
var timer:Number=20;
function TimeStep(evt:Event):void {
if (timer==0) {
defaultGroup.removeParticle(ground3);
var rectangle1: RectangleParticle = new RectangleParticle(150, -100,
80, 2, 45, false, 10, 0.3, .5);
defaultGroup.addParticle(rectangle1);
rectangle1.setStyle(0, 0xFF0000, 1, 0xFF0000,0.5);
}
if (timer==-40) {
trace(timer);
defaultGroup.removeParticle(rectangle1);
}
timer--;
APEngine.step();
APEngine.paint();
}
The problem in in the TimeStep function. The following code:
defaultGroup.removeParticle(rectangle1); does not execute properly.
Any help would be very much appreciated. Thank you very much for your
time.