ローダーオブジェクトからのビットマップデータがあり、タイルとして使用するために32x32の正方形にスライスしたいと思います。それを行う最も効率的な方法は何ですか?Actionscript 3:ビットマップをタイルにスライスする
1
A
答えて
1
BitmapData
ファンクションcopyPixels
を使用できます(linkを参照)。これを使用すると、ソースBitmapDataの1つの領域(Rectangleで指定)から、BitmapData
の特定のPoint
にピクセルをコピーできます。基本的には、各32x32四角形に対して新しいBitmapData
を作成し、ロードされたオブジェクトをループさせて、copyPixels
で四角形を埋めることができます。
5
私はあなたのために仕事をしました。基本的な考え方は、BitmapData関数copyPixelsを使用することです。アドビリファレンスを参照してください。これを使用すると、ソースBitmapDataの1つの領域(Rectangleで指定)から、転送先BitmapData内の特定のPointにピクセルをコピーできます。私は32x32の正方形ごとに新しいBitmapDataを作成し、ロードされたオブジェクトをループして、copyPixelsで四角形を設定しました。
var imageLoader:Loader;
function loadImage(url:String):void
{
// Set properties on my Loader object
imageLoader = new Loader();
imageLoader.load(new URLRequest(url));
imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
}
loadImage("Cow Boy.jpg");//--------->Replace this by your image. I hope you know to specify path.
function imageLoaded(e:Event):void
{
// Load Image
imageArea.addChild(imageLoader);
var mainImage:BitmapData = new BitmapData(imageArea.width,imageArea.height);
var tileX:Number = 36;
var tileY:Number = 36;
var bitmapArray:Array;
var tilesH:uint = Math.ceil(mainImage.width/tileX); // Number of Columns
var tilesV:uint = Math.ceil(mainImage.height/tileY);// Number of Rows
mainImage.draw(imageArea);
imageArea.x += 500;
bitmapArray = new Array();
for (var i:Number = 0; i < tilesH; i++)
{
bitmapArray[i] = new Array();
for (var n:Number = 0; n < tilesV; n++)
{
var tempData:BitmapData=new BitmapData(tileX,tileY);
var tempRect = new Rectangle((tileX * i),(tileY * n),tileX,tileY);
tempData.copyPixels(mainImage,tempRect,new Point(0,0));
bitmapArray[i][n]=tempData;
}
}
for (var j:uint =0; j<bitmapArray.length; j++)
{
for (var k:uint=0; k<bitmapArray[j].length; k++)
{
var bitmap:Bitmap=new Bitmap(bitmapArray[j][k]);
this.addChild(bitmap);
bitmap.x = (j+1)* bitmap.width + j*10;
bitmap.y = (k+1)* bitmap.height + k*10;
}
}
}
function imageLoading(e:ProgressEvent):void
{
// Use it to get current download progress
// Hint: You could tie the values to a preloader :)
}
関連する問題
- 1. actionscriptでビットマップをトレースする
- 2. 画像をタイルにスライスします
- 3. StateListDrawableとタイル張りのビットマップ
- 4. スプライトがActionScript 3でビットマップを共有する必要がありますか?
- 5. Android開発:小さなタイル/ビットマップを1つのビットマップにまとめる
- 6. actionscript 2コードをactionscript 3に変換するには?
- 7. ActionScript:ビットマップをクラスに正しくキャストする
- 8. ActionScript 3.0:JPEGエンコードByteArrayをビットマップに変換する方法
- 9. ボトムアライメントを使用してタイル状のビットマップを描画する
- 10. XMLをActionscript 3にロードする
- 11. actionscript 3ローテーション
- 12. Actionscript 3 Facebook integration
- 13. actionscript 3 init()
- 14. arsort with Actionscript 3
- 15. ActionScript 3スプライトエンベロープ
- 16. ActionScript 3アルファトゥイーン
- 17. Actionscript 3 Json?
- 18. Actionscript 3 Array
- 19. ActionScript 3のコンボボックス
- 20. Actionscript 3 and XML
- 21. ActionScript 3:Bullet Ricocheting
- 22. Admob&ActionScript 3
- 23. ActionScript 3 Mouse Out
- 24. Actionscript 3 EventListener
- 25. ActionScript 3のevent.target
- 26. help-actionscript 3シンプルボタンクラス
- 27. Actionscript 3オンスクリーンキーボード
- 28. ActionScript 3&ランタイムリソース
- 29. アンロードコンテンツ - メインメニューactionscript 3
- 30. actionscriptのダイナミックステージ3
それを行うための最善の方法は、* *タイルに分割ではなく、(答えで述べたようにCopyPixelsを使用して)先のキャンバスに、元のソーステクスチャから直接タイルをブリットしないことです。 –