I threw this together quick today to help me push out some physics maps for a game I am creating using the APE physics engine.
I am brand new to AS 3, so I have no idea wtf I am doing. terribly typed, but still a useful script if you're working with APE.
it requires a library clip with a linkage name"midPointClip" if you want to mark the center of the collision surface.
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouse_down); stage.addEventListener(MouseEvent.MOUSE_UP, mouse_up); stage.addEventListener(MouseEvent.MOUSE_MOVE, moving);
stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = "TL";
this.width = stage.width*1; this.height = stage.height*1; var lines = []; var newLine:MovieClip; var line:Shape; var drawing = false;
function angle(p1,p2,radians){ var degrees = -Math.atan2((p1.x-p2.x), (p1.y-p2.y))/(Math.PI/180); if(radians){ return (90+degrees) * (Math.PI/180); } else{ return degrees; }
}
function moving(e:MouseEvent) { sketchLine(); }
function mouse_down(e:MouseEvent) {
newLine = new MovieClip();
line = new Shape();
addChild(newLine);
newLine.startPoint = new Point(newLine.mouseX,newLine.mouseY);
line.graphics.moveTo(newLine.mouseX,newLine.mouseY);
newLine.addChild(line);
drawing = true;
}
var s = 0;
function mouse_up(e:MouseEvent) {
drawing = false;
newLine.endPoint = new Point(newLine.mouseX,newLine.mouseY);
newLine.lineLength = Point.distance(newLine.startPoint,newLine.endPoint);
newLine.midPoint = Point.interpolate(newLine.startPoint,newLine.endPoint,0.5);
var midClip
isplayObject = new midPointClip();
midClip.x = newLine.midPoint.x;
midClip.y = newLine.midPoint.y;
newLine.addChild(midClip);
s++;
trace("surface"+s+" = new RectangleParticle("+
newLine.midPoint.x+","+
newLine.midPoint.y+","+
newLine.lineLength+","+
"2,"+
angle(newLine.startPoint,newLine.endPoint,true)+","+
"true);");
trace("surface"+s+".visible = true;");
trace("addParticle("+"surface"+s+");");
trace("");
}
function sketchLine() { if (drawing) { line.graphics.clear(); line.graphics.lineStyle(0,0x000000); line.graphics.moveTo(newLine.startPoint.x,newLine.startPoint.y); line.graphics.lineTo(newLine.mouseX,newLine.mouseY);
}
}
var drawDyn:Timer = new Timer(10, 0); drawDyn.addEventListener("timer", sketchLine);
with some edge detection using the bitmap object... might be able to sort of drape a mesh on a color field and have it output a map...on the fly.
just tried the code. It draws a line between two points and places a movie at the average? What am i missing not sure why angle is needed or some of the other code seems overkill what can it do extra?
Ah, you take the trace and place it into a surface group class within APE.
the angle is needed so you can inform ape what the angle of the surface is.
For example a single surface trace might look like:
surface1 = new RectangleParticle(1742.6000000000001,1725.0500000000002,28.284271247461902,2,0.7853981633974483,true); surface1.visible = true; surface1.setStyle(0, colD, 1, colD); addParticle(surface10);"
Which I can put into a class:
package {
import org.cove.ape.*;
public class level extends Group {
var surface1:RectangleParticle;
public function level(colA:uint, colB:uint, colC:uint, colD:uint, colE:uint) {
surface1 = new RectangleParticle(1231.3000000000002,1386.25,336.54494499249284,2,2.909225934342985,true);
surface1.visible = true;
surface1.setStyle(0, colD, 1, colD);
addParticle(surface1);
}
}
}
So its just a fast way to make a code generator for a APE map. But I posted it cause I am all proud. Its sort of my first AS 3 code ever. I been stuck in AS 2 land for a long time. XD
ah like so a landrover can drive over a landscape or something.
Might be worth having NewLine extend Sprite then you can move the drawing calculations inside it...
private function mouse_down(e:MouseEvent):void { newLine = new NewLine( new Point( mouseX, mouseY ) ); addChild( newLine );
} private function sketchLine():void { if( newLine!=null ){ newLine.endPoint = new Point( mouseX, mouseY ); } } private function mouse_up(e:MouseEvent):void { sketchLine(); trace("surface"+s+" = new RectangleParticle("+ newLine.midPoint.x+","+ newLine.midPoint.y+","+ newLine.lineLength+","+ "2,"+ angle(newLine,true)+","+ "true);"); trace("surface"+s+".visible = true;"); trace("addParticle("+"surface"+(s++)+");"); trace(""); newLine = null; }
nice.
thanks!
Originally posted by: persist I am brand new to AS 3 :shock and awe:
I'm kind of surprised too, to tell you the truth.

I haven't been around for a while and knew persist had been working in other area's for the last 12 months, also something to do with spending more family time than he had been previously as well as the new SL interests. Hey, we all come and go for various reasons and have been around here long enough to realise that events occur that aren't always stated with full details.
Persist, I'm still awestruck that even when you're learning something new your output is still of a high standard. It's also great to see JLM who you used to hand out pointers to be able to reciprocate and now give something back. Your work's first class persist and always a pleasure to follow, thanks for sharing.
Honestly just needed a break from Flash. You know you wake up one day and realize you have been coding on the same platform for 8 years. What I have heard from fellow developers is 7 years is usually the burn out.
In the coming economy, 3d and video work will be mixing with 2d development at an unprecedented level as entertainment and marketing budgets are forced to funnel into single deployments rather than massive multichannel and expensive parallel developments. Clients are gonna want more bang per project.They're gonna want all the eye candy they're used to seeing, but they're going to want it on a single platform, and they're going to rely on social computing to get people there. So my interest in AS 3 has become a goal to be adequate in the skill, rather than make it the hub of my skills set.
I have been concentrating on improving my 3d and video skills, with the expectation that I have enough code experience to put together a delivery method in whatever best suits the client.
Until recently, the performance gains in AS have been pointless. We got with AS 3 more frame rate, and performance, but for all that they gave us the same old ui form components. It's just recently that video, bitmap and video card support are making the move to AS 3 relevant.
Persist tried haXe yet?