我試圖在隨機位置繪製兩個圓圈,並在這兩個圓圈之間繪製一條線 - 但閃光似乎沒有在我的圓圈中註冊x | y座標碼。我將如何做到這一點。更好的是,我該如何做到這一點,如果我拖動其中一個圓圈,這條線將保持這些點之間的連接?這裏是我的代碼:flash as3在兩個圓圈之間繪製一條線
var sw = stage.stageWidth;
var sh = stage.stageHeight;
var cr = 6; //circle radius
var circleColor = 0x000000;
var numCircles = 2;
var circleArray = [];
var lineCanvas:Sprite = new Sprite();
addChild(lineCanvas);
var lineColor = 0x000000;
var lineWeight = 1;
function init(){
drawCircle();
}
function drawCircle(){
for (var i = 0; i<numCircles; i++){
var xPos = randomRange(cr, sw-cr);
var yPos = randomRange(cr, sh-cr);
var newCircle:Shape = new Shape();
newCircle.graphics.beginFill(circleColor);
newCircle.graphics.drawCircle(xPos,yPos,cr);
newCircle.graphics.endFill();
circleArray.push(newCircle);
addChild(newCircle);
}
drawLine();
}
function drawLine(){
for (var i = 0; i<numCircles-1; i++){
trace (circleArray[i].x);
lineCanvas.graphics.lineStyle(lineWeight,lineColor);
lineCanvas.graphics.moveTo(circleArray[i].x,circleArray[i].y);
lineCanvas.graphics.lineTo(circleArray[i+1].x,circleArray[i+1].y);
}
}
function randomRange(minNum:Number, maxNum:Number):Number {
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
init();
是的,絕對正確:) –