package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.events.Event;
public class Init extends Sprite {
var rects:Array,
numRects:int = stage.stageWidth / _width + 1,
_width:Number = 20,
_height:Number = 80,
_rotation:int = 0;
public function Init() {
init();
}
function init():void
{
rects = new Array();
for(var i:int = 0; i < numRects; i++)
{
var rect:Rect = new Rect();
rect.x = i * 20;
addChild(rect);
rects.push(rect);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
function onEnterFrame(e:Event):void
{
for(var i:int = 0; i < numRects; i++)
{
rects[i].rotationY += 1;
}
_rotation += 1;
if(_rotation % 180 == 0)
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
}
}
这是Rect类:
package {
import flash.display.Sprite;
public class Rect extends Sprite {
private var color:uint,
_width:Number,
_height:Number;
public function Rect(color:uint = 0x000000, width:Number = 20, height:Number = 80) {
this.color = color;
this._width = width;
this._height = height;
init();
}
function init():void
{
graphics.beginFill(color);
graphics.drawRect(0, 0, _width, _height);
graphics.endFill();
}
}
}
所以我创建了许多矩形并将每个循环移动了20个像素,所以到现在它们都填充了颜色,但是如果我有一个高大的图像高度等于这些矩形,并切割该图像并填充其中的每一个矩形与图像的一部分,就像制作拼图部分一样,我已将图像导入我的图书馆,但现在我不知道如何做到这一点请任何想法?
答案 0 :(得分:1)
简而言之:如果要拆分图像,请使用位图作为Rect子项或基础,并使用基础BitmapData.copyPixels()
方法用一个大图像中的像素填充您的rects'位图。一个例子:
var megabase:BitmapData = new BigImage().bitmapData; // BigImage is an embedded asset name
_sequence = new Vector.<BitmapData>();
_rect = new Rectangle(0, 0, 64, 64); // my parts of image are 64x64 all, in general you should have (x,y,w,h) declared somewhere
_point = new Point();
var smallBD:BitmapData;
_sequence = new Vector.<BitmapData>();
for (i = 0; i < ssa.length; i++) {
// ssa is a (x,y) array defining areas that each sprite will contain
smallBD = new BitmapData(64, 64, true, 0);
_rect.x = ssa[i][0];
_rect.y = ssa[i][1];
smallBD.copyPixels(megabase, _rect, _point);
_sequence.push(smallBD);
}
这将一个巨大的megabase
图像分割成几个64x64图像,这些图像被排列为BitmapData对象的Vector。你显然会有一个不同的底层结构,但主要原则在这里说明。