-
package
-
{
-
import flash.display.Bitmap;
-
import flash.display.BitmapData;
-
import flash.display.Sprite;
-
import flash.events.Event;
-
import flash.display.StageAlign;
-
import flash.display.StageScaleMode;
-
import flash.events.MouseEvent;
-
import flash.geom.Matrix;
-
import flash.geom.Point;
-
import flash.ui.Mouse;
-
import flash.ui.MouseCursor;
-
-
/**
-
* エンドレスビットマップ
-
* @author Shinro Kato(ipuheke)
-
*/
-
public class Main extends Sprite
-
{
-
[Embed(source='../lib/endless.gif')]
-
private var bmpClass:Class;
-
private var bmp_mt:Bitmap;
-
-
private var sp:Sprite;
-
-
private var dragStartPoint:Point;
-
-
private var matrix:Matrix;
-
-
-
/**
-
* コンストラクタ
-
*/
-
public function Main():void
-
{
-
if (stage) init();
-
else addEventListener(Event.ADDED_TO_STAGE, init);
-
}
-
-
-
/**
-
* 初期化
-
* @param e
-
*/
-
private function init(e:Event = null):void
-
{
-
removeEventListener(Event.ADDED_TO_STAGE, init);
-
// entry point
-
-
stage.align = StageAlign.TOP_LEFT;
-
stage.scaleMode = StageScaleMode.NO_SCALE;
-
-
stage.addEventListener(MouseEvent.MOUSE_DOWN, stageMouseDown);
-
-
//basePointを定義
-
basePoint = new Point();
-
dragStartPoint = new Point();
-
-
//matrix
-
matrix = new Matrix();
-
-
-
//bmpを定義
-
bmp_mt = new bmpClass() as Bitmap;
-
-
//spriteを定義
-
sp = new Sprite();
-
sp.graphics.beginBitmapFill(bmp_mt.bitmapData);
-
sp.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
-
sp.graphics.endFill();
-
addChild(sp);
-
-
//マウスカーソル(手)
-
Mouse.cursor = MouseCursor.HAND;
-
}
-
-
-
/**
-
* マウスダウン
-
* @param e
-
*/
-
private function stageMouseDown(e:MouseEvent):void {
-
//押された場所
-
dragStartPoint.x = e.stageX;
-
dragStartPoint.y = e.stageY;
-
-
sp.addEventListener(MouseEvent.MOUSE_MOVE, stageMouseMove);
-
sp.addEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
-
}
-
-
/**
-
* マウスムーブ
-
* @param e
-
*/
-
private function stageMouseMove(e:MouseEvent):void {
-
-
//matrixのズレ(最小で良いのでタイルのサイズで割った余りでよい)
-
matrix.tx -= (dragStartPoint.x - e.stageX) % bmp_mt.width;
-
matrix.ty -= (dragStartPoint.y - e.stageY) % bmp_mt.height;
-
-
dragStartPoint.x = e.stageX;
-
dragStartPoint.y = e.stageY;
-
-
//Spriteに描き込む
-
sp.graphics.clear();
-
sp.graphics.beginBitmapFill(bmp_mt.bitmapData,matrix);
-
sp.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
-
sp.graphics.endFill();
-
}
-
-
/**
-
* マウスアップ
-
* @param e
-
*/
-
private function stageMouseUp(e:MouseEvent):void {
-
sp.removeEventListener(MouseEvent.MOUSE_MOVE, stageMouseMove);
-
sp.removeEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
-
}
-
-
}
-
-
}