Skip to content

Instantly share code, notes, and snippets.

@connery0
Created September 9, 2014 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save connery0/0abd09b1d81774022502 to your computer and use it in GitHub Desktop.
Save connery0/0abd09b1d81774022502 to your computer and use it in GitHub Desktop.
Rescaling Isometric Tile
package TileGenerationTest
{
import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;
import net.flashpunk.FP;
import net.flashpunk.graphics.Image;
/**
* ...
* @author Connery0
*/
public class Tile extends Image
{
private var topTile:BitmapData;
private var middleTile:BitmapData;
private var bottomTile:BitmapData;
private const topHeight:Number = 48;
private const middleHeight:Number = 52;
private const botttomHeight:Number = 24;
private const tileWidth:Number = 90;
public function Tile(source:*, Height:Number)
{
super(source);
ChangeHeight(Height);
}
private function ChangeHeight(tileHeight:Number):void
{
var Zero:Point = new Point();
var TempBitmap:BitmapData = new BitmapData(tileWidth, topHeight);
var Result:BitmapData = new BitmapData(tileWidth, topHeight + tileHeight + botttomHeight);
TempBitmap.copyPixels(source, new Rectangle(0, 0, tileWidth, topHeight), Zero);
topTile = TempBitmap;
if (tileHeight > 0)
{
TempBitmap = new BitmapData(90, tileHeight);
for (var TempHeight:int = tileHeight; TempHeight > 0; )
{
if (TempHeight > middleHeight)
{
TempBitmap.copyPixels(source, new Rectangle(0, topHeight, 90, middleHeight), new Point(0, tileHeight - TempHeight));
TempHeight = TempHeight - middleHeight;
}
else
{
TempBitmap.copyPixels(source, new Rectangle(0, topHeight, 90, TempHeight), new Point(0, tileHeight - TempHeight));
TempHeight = TempHeight - middleHeight;
}
}
middleTile = TempBitmap;
}
TempBitmap = new BitmapData(90, 24);
TempBitmap.copyPixels(source, new Rectangle(0, 100, 90, 24), Zero);
bottomTile = TempBitmap;
Result.copyPixels(topTile, new Rectangle(0, 0, topTile.width, topTile.height), Zero);
if (tileHeight > 0)
{
Result.copyPixels(middleTile, new Rectangle(0, 0, middleTile.width, middleTile.height), new Point(0, topTile.height))
}
;
Result.copyPixels(bottomTile, new Rectangle(0, 0, bottomTile.width, bottomTile.height + tileHeight), new Point(0, topTile.height + tileHeight));
_source = Result;
_sourceRect = _source.rect;
createBuffer();
updateBuffer();
this.y = -tileHeight
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment