天天看點

flash分割美女圖拼圖遊戲

能把一張圖檔分割成若幹份,份數由輸入數字自由決定。分割後自動随機打亂位置,可以拖到,拖到到正确位置自動吸附,并不允許再抛動。基本能算一個拼圖遊戲的雛形了吧。但整到這裡就不想整了。能用右鍵加載自己的圖檔。以下是無聊的代碼:

import flash.net.FileReference;

import flash.display.BitmapData;

import flash.geom.Matrix;

/

var img_bmp:BitmapData = new BitmapData(mc._width, mc._height);

var txt_fmt:TextFormat = new TextFormat();

txt_fmt.color = 0xff00ff;

txt_fmt.size = 22;

txt_fmt.font = "華文新魏";

/

for (var d:Number = 2; d>0; d--) {

this.createTextField("wh_txt"+d, 9000+d, d*100, 20, 50, 26);

this["wh_txt"+d].setNewTextFormat(txt_fmt);

this["wh_txt"+d].border = true;

this["wh_txt"+d].input = true;

this["wh_txt"+d].type = "input";

this["wh_txt"+d].maxChars = 1;

this["wh_txt"+d].restrict("0-9");

this["wh_txt"+d].background = true;

this["wh_txt"+d].borderColor = 0xff9900;

this["wh_txt"+d].backgroundColor = 0x33cccc;

}

Selection.setFocus("wh_txt1");

//

wh_txt1.onChanged = wh_txt2.onChanged=function () {

if (wh_txt1.text == "") {

  Selection.setFocus("wh_txt1");

} else if (wh_txt2.text == "") {

  Selection.setFocus("wh_txt2");

} else {

  fenge_func(wh_txt1.text, wh_txt2.text);

}

};

var xwpos:Number = 0;

var yhpos:Number = 0;

function fuwei_func() {

for (var d:Number = xwpos-1; d>=0; d--) {

  for (var c:Number = yhpos-1; c>=0; c--) {

   this["pic_mc"+d+c].removeMovieClip();

  }

}

}

//

function fenge_func(xw:Number, yh:Number) {

fuwei_func();

xwpos = xw;

yhpos = yh;

img_bmp.draw(mc, new Matrix());

var xy_array:Array = new Array();

var b_num:Number = new Number();

for (var d:Number = xw-1; d>=0; d--) {

  for (var c:Number = yh-1; c>=0; c--) {

   this.createEmptyMovieClip("pic_mc"+d+c, 200+d+""+c);

   this["pic_mc"+d+c].lineStyle(1, 0xfff000, 100);

   this["pic_mc"+d+c].beginBitmapFill(img_bmp, new Matrix(), false);

   this["pic_mc"+d+c].moveTo(d*Stage.width/xw, c*Stage.height/yh);

   this["pic_mc"+d+c].lineTo((d+1)*Stage.width/xw, c*Stage.height/yh);

   this["pic_mc"+d+c].lineTo((d+1)*Stage.width/xw, (c+1)*Stage.height/yh);

   this["pic_mc"+d+c].lineTo(d*Stage.width/xw, (c+1)*Stage.height/yh);

   this["pic_mc"+d+c].lineTo(d*Stage.width/xw, c*Stage.height/yh);

   this["pic_mc"+d+c].endFill();

   this["pic_mc"+d+c].obj = new Object();

   this["pic_mc"+d+c].obj = this["pic_mc"+d+c].getBounds(_root);

   this["pic_mc"+d+c].xpos = this["pic_mc"+d+c].obj.xMin;

   this["pic_mc"+d+c].ypos = this["pic_mc"+d+c].obj.yMin;

   var xy2_array:Array = new Array();

   xy2_array.push(this["pic_mc"+d+c].obj.xMin, this["pic_mc"+d+c].obj.yMin);

   xy_array.push(xy2_array);

   this["pic_mc"+d+c].id = d+""+c;

   //

   this["pic_mc"+d+c].onPress = function() {

    b_num = this.id;

    this.swapDepths(this._parent.getNextHighestDepth());

    this.startDrag();

本文轉自:http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/1230.html