📄 scrollbitmapdata.as
字号:
/**
* Copyright (c) 2008 Bartek Drozdz (http://www.everydayflash.com)
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package com.everydayflash.bitmap {
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;
public class ScrollBitmapData extends BitmapData {
private var source:BitmapData;
private var zero:Point = new Point(0, 0);
private var dx:int;
private var dy:int;
private var w:int;
private var h:int;
public function ScrollBitmapData(width:int, height:int, transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF) {
super(width, height, transparent, fillColor);
dx = 0;
dy = 0;
}
public function setSource(source:BitmapData):void {
this.source = source;
w = source.width;
h = source.height;
copyPixels(source, source.rect, zero);
}
public function scrollBy(x:Number, y:Number):void {
lock();
//dx = (dx + x) % w;
//if (dx < 0) dx = w - dx;
//copyPixels(source, new Rectangle(dx, 0, w, h), zero);
//copyPixels(source, new Rectangle(0, 0, dx, h), new Point(w - dx, 0));
x = Math.round(x);
y = Math.round(y);
if (x > 0) {
copyPixels(source, new Rectangle(x, 0, width, height), zero);
copyPixels(source, new Rectangle(0, 0, x, height), new Point(width-x, 0));
source.copyPixels(this, rect, zero);
} else if (x < 0) {
x = Math.abs(x);
copyPixels(source, new Rectangle(width-x, 0, x, height), zero);
copyPixels(source, new Rectangle(0, 0, width-x, height), new Point(x, 0));
source.copyPixels(this, rect, zero);
}
//dy = (dy + y) % h;
//if (dy < 0) dy = h - dy;
//copyPixels(source, new Rectangle(0, dy, w, h), zero);
//copyPixels(source, new Rectangle(0, 0, w, dy), new Point(0, h-dy));
if (y > 0) {
copyPixels(source, new Rectangle(0, y, width, height), zero);
copyPixels(source, new Rectangle(0, 0, width, y), new Point(0, height-y));
source.copyPixels(this, rect, zero);
} else if (y < 0) {
y = Math.abs(y);
copyPixels(source, new Rectangle(0, height-y, width, y), zero);
copyPixels(source, new Rectangle(0, 0, width, height-y), new Point(0, y));
source.copyPixels(this, rect, zero);
}
unlock();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -