Skip to content

Instantly share code, notes, and snippets.

@alijaya
Created June 23, 2013 13:04
Show Gist options
  • Save alijaya/5844981 to your computer and use it in GitHub Desktop.
Save alijaya/5844981 to your computer and use it in GitHub Desktop.
Snippet for BitmapData slicing
var bd = Assets.getBitmapData("path/to/image.png");
var a : Array<Array<BitmapData>> = [];
var xCount = 5; // berapa banyak tile horizontal
var yCount = 5; // berapa banyak tile vertikal
var tileWidth = Std.int(bd.width/xCount); // dibulatkan kebawah
var tileHeight = Std.int(bd.height/yCount); // dibulatkan kebawah
for(j in 0...yCount)
{
a.push([]);
for(i in 0...xCount)
{
var temp = new BitmapData(tileWidth, tileHeight, true, 0); // buat BitmapData dengan width = tileWidth, height = tileHeight
temp.copyPixels(bd, new Rectangle(i*tileWidth,j*tileHeight,tileWidth,tileHeight), new Point(0, 0)); // copy pixel dari bd di daerah persegi dengan koordinat x = i*tileWidth, y = j*tileHeight, width = tileWidth, height = tileHeight, ke temp di posisi x = 0, y = 0
a[j].push(temp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment