i got function internet slice image part tiles , put them in array (linear or multidimensional).
---example---
var sliceclips:array = slicemovieclip({source:sourcemovieclip, target:tilescontainer, cols:7, rows:5}).linear; so function:
private function slicemovieclip(o:object):object { var returnarray:array = new array(); var arraylinear:array = new array(); var array2d:array = new array(); var cols:uint = o.cols; var rows:uint = o.rows; var tilewidth:uint = o.source.width / cols; var tileheight:uint = o.source.height / rows; var rect:rectangle = new rectangle(0,0,tilewidth,tileheight); var pnt:point = new point(); var imagebmpd:bitmapdata = new bitmapdata(o.source.width,o.source.height,true,0x000000); var imagebmp:bitmap = new bitmap(imagebmpd); imagebmpd.draw(o.source); (var ty:uint = 0; ty < rows; ty++) { var arrayrow:array = new array(); (var tx:uint = 0; tx < cols; tx++) { var sourcerect:rectangle = new rectangle(tx * tilewidth,ty * tileheight,tilewidth,tileheight); var destpoint:point = new point(0,0); var tilebmpd:bitmapdata = new bitmapdata(tilewidth,tileheight,true,0x000000); var tilebmp:bitmap = new bitmap(tilebmpd); var tilemcl:movieclip = new movieclip(); tilemcl.addchild(tilebmp); tilebmpd.copypixels(imagebmpd, sourcerect, destpoint); tilemcl.x = tx * tilewidth; tilemcl.y = ty * tileheight; o.target.addchild(tilemcl); returnarray.push(tilemcl); arrayrow.push(tilemcl); } array2d.push(arrayrow); } return {linear:arraylinear, multi:array2d}; } i'm trying add stage part of image sliced different spot function (look @ last if):
private function buildmap(e:event):void { (var i:int=0; i<visareay; i++) { (var u:int=0; u<visareax; u++) { if ((mapid[i][u]) == 0) { var cell:movieclip = new tile(); cell.gotoandstop(mapid[i][u]+1); cell.x = tileside * u; cell.y = tileside * i; addchild(cell); } if ((mapid[i][u]) == 1) { var cell2:movieclip = new blacksquare(); cell2.gotoandstop(mapid[i][u]+1); cell2.x = tileside * u; cell2.y = tileside * i; addchild(cell2); } if ((mapid[i][u]) == 2) { var cell3:movieclip = sliceclips[2][0]; cell3.gotoandstop(mapid[i][u]+1); cell3.x = tileside * u; cell3.y = tileside * i; trace("obj: " + cell3 + " w:" + cell3.width + " h:" + cell3.height + " pos:" + cell3.x + " " + cell3.y); addchild(cell3); } } } } there problem cell3 (which use sliced image) cause seem use same image , doesnt duplicate on stage, if have 4 time on map show image on last tile.
i trying do:
var cell3:movieclip = new sliceclips[2][0]; but won't accept "new" cause not class.
any idea how can work out? how can set movieclip array class or something.. i'm beginner in as3
given sliced images use single bitmap object, best can clone bitmap new mc.
if ((mapid[i][u]) == 2) { var cell3:movieclip = new movieclip(); cell3.addchild(new bitmap((sliceclips[2][0].getchildat(0) bitmap).bitmapdata)); // main magic happens here ^ bitmapdata of source mc // make new bitmap , new mc cell3.x = tileside * u; cell3.y = tileside * i; trace("obj: " + cell3 + " w:" + cell3.width + " h:" + cell3.height + " pos:" + cell3.x + " " + cell3.y); addchild(cell3); }
Comments
Post a Comment