어제 올렸던 대시라인 그리기에서 조금 더 기능을 추가해 봤습니다. 포토샵에서 선택영역을 지정하면 점선이 이동하는 효과가 나오는데, 그걸 적용했습니다. 행진하는 개미 ^^
beginBitmapFill(bitmap:BitmapData, matrix:Matrix=null, repeat:Boolean=true, smooth:Boolean=false):void
위와 같이 Graphics.beginBitmapFill() 메소드에 2번째 파라메터로 매트릭스를 지정하여 사용할 수 있습니다. 그래서 하나의 비트맵데이터를 가지고 매트릭스에 회전을 주어서 사용을 했더니, 비트맵데이터가 외곡되는 문제가 생기네요. 일단 귀찮아서 비트맵데이터 4개를 가지고 그렸는데, 최적화하는 방법은 좀 더 찾아 봐야할 듯 하네요.
import flash.display.*;
import flash.geom.Rectangle;
import flash.events.MouseEvent;
import flash.text.*;
import flash.geom.Matrix;
import flash.utils.Timer;
import flash.events.TimerEvent;
var fmt:TextFormat = new TextFormat("Arial", 14, 0x666666);
var tf:TextField = new TextField();
tf.defaultTextFormat = fmt;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.text = "Drag on the stage";
tf.selectable = false;
tf.x = (stage.stageWidth - tf.width) / 2;
tf.y = (stage.stageHeight - tf.height) / 2;
addChild(tf);
var rightBD:BitmapData = new BitmapData(10, 1, true, 0x0);
rightBD.fillRect(new Rectangle(0, 0, 5, 1), 0xFF000000);
var leftBD:BitmapData = new BitmapData(10, 1, true, 0x0);
leftBD.fillRect(new Rectangle(5, 0, 5, 1), 0xFF000000);
var downBD:BitmapData = new BitmapData(1, 10, true, 0x0);
downBD.fillRect(new Rectangle(0, 0, 1, 5), 0xFF000000);
var upBD:BitmapData = new BitmapData(1, 10, true, 0x0);
upBD.fillRect(new Rectangle(0, 5, 1, 5), 0xFF000000);
var sp:Sprite = new Sprite();
sp.x = sp.y = 20;
addChild(sp);
function drawLine(w:Number, h:Number):void
{
var grp:Graphics = sp.graphics;
grp.clear();
// right
grp.lineStyle(1);
grp.lineBitmapStyle(rightBD);
grp.lineTo(w, 0);
grp.endFill();
// down
grp.lineStyle(1);
grp.lineBitmapStyle(downBD);
grp.lineTo(w, h);
grp.endFill();
// left
grp.lineStyle(1);
grp.lineBitmapStyle(leftBD);
grp.lineTo(0, h);
grp.endFill();
// up
grp.lineStyle(1);
grp.lineBitmapStyle(upBD);
grp.lineTo(0, 0);
grp.endFill();
}
drawLine(560, 360);
stage.addEventListener(MouseEvent.MOUSE_DOWN, downListener);
function downListener(e:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveListener);
stage.addEventListener(MouseEvent.MOUSE_UP, upListener);
moveListener();
}
function moveListener(e:MouseEvent=null):void
{
drawLine(sp.mouseX, sp.mouseY);
}
function upListener(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveListener);
stage.removeEventListener(MouseEvent.MOUSE_UP, upListener);
moveListener();
}
var timer:Timer = new Timer(150, 0);
timer.addEventListener(TimerEvent.TIMER, timerListener);
function timerListener(e:TimerEvent):void
{
var c:int;
c = rightBD.getPixel32(9, 0);
rightBD.scroll(1, 0);
rightBD.setPixel32(0, 0, c);
c = downBD.getPixel32(0, 9);
downBD.scroll(0, 1);
downBD.setPixel32(0, 0, c);
c = leftBD.getPixel32(0, 0);
leftBD.scroll(-1, 0);
leftBD.setPixel32(9, 0, c);
c = upBD.getPixel32(0, 0);
upBD.scroll(0, -1);
upBD.setPixel32(0, 9, c);
}
timer.start();
답글 남기기