來把之前寫過的 Flash 程式片段功能整理一下(其實是 iammic 不知道要寫什麼了>"<)。在 Flash 中撰

寫拼圖, 會將圖片進行切割後,在亂數擺放切割後的圖片內容,以下則為 iammic 之前寫的 Flash 拼圖

遊戲中整理出來的 Flash 切圖範例。

 

Flash 效果:(左邊為切割後效果,右邊為原圖)

image

 

Flash 程式:

package ImageCut
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.display.Bitmap;    
    import flash.display.BitmapData;
    import flash.geom.Rectangle;
    import flash.geom.Point;
    import flash.display.Sprite;
 
    /**
     * ...
     * @author 
     */
    public class Main extends Sprite 
    {        
        
        [Embed(source = '/../lib/1.png')]
        private var Source:Class; //來源圖檔
        private var source:Bitmap = new Source();
        
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            
            //來源圖檔
            source.x = 220;
            source.y = 0
            addChild(source);    
            
            //切割圖檔
            var img:Bitmap = new Source();            
            var num :int= 0;
            for(var i:int=1;i<=2;i++){
                for(var j:int=1;j<=2;j++){
                    var img1:Bitmap=new Bitmap(new BitmapData(200,110));
                    img1.bitmapData.copyPixels(img.bitmapData, new Rectangle((j - 1) * 200, (i - 1) * 110, i * 200, j * 110), new Point(0, 0));                        
                    img1.x = 0
                    img1.y = num * 120;
                    addChild(img1)
                    num++;
                }
            }
            
        }
                
        
    }
    
}

 

檔案下載:ImageCut.zip ( FlashDevelop AS3 Project )

arrow
arrow
    全站熱搜

    iammic 發表在 痞客邦 留言(0) 人氣()