29Jan
[AS 3] Drawing Lines across the Stage
No commentsToday I just wanted to display a defined numer of lines with various angles to span across the stage.. nothing too exciting here, but this will be the groundwork for some future projects that I have going on:
Here is the basic Line.as file:
package {
import flash.display.Sprite;
import flash.display.Graphics;
import flash.geom.Rectangle;
public class Line extends Sprite {
public var moveToX:Number;
public var moveToY:Number;
public var lineToX:Number;
public var lineToY:Number;
public function Line(moveToX:Number=0,moveToY:Number=0,lineToX:Number=50,lineToY:Number=0) {
graphics.lineStyle(1);
graphics.moveTo(moveToX,moveToY);
graphics.lineTo(lineToX,lineToY);
}
}
}
Here is the document class file Landscape.as
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class Landscape extends Sprite
{
private var ball:Ball;
private var line:Line;
private var lines:Array;
private var numLines:Number = 8;
private var moveLineX:Number;
private var moveLineY:Number;
private var xIteration:Number = stage.stageWidth / numLines;
private var beginLineX:Number;
private var beginLineY:Number;
public function Landscape()
{
init();
}
private function init():void
{
moveLineX = 0;
moveLineY = Math.random() * stage.stageHeight;
beginLineX = xIteration;
beginLineY = Math.random() * stage.stageHeight;
for (var i:uint = 0; i < numLines; i++)
{
line = new Line(moveLineX,moveLineY,beginLineX,beginLineY);
addChild(line);
moveLineX = beginLineX;
moveLineY = beginLineY;
beginLineX = (i + 2) * xIteration;
beginLineY = Math.random() * stage.stageHeight;
}
}
}
}
Categories: Actionscript 3, Drawing API
Tuesday, January 29th, 2008 at 11:11 am and is filed under Actionscript 3, Drawing API. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.