Created
September 9, 2014 10:57
-
-
Save connery0/0abd09b1d81774022502 to your computer and use it in GitHub Desktop.
Rescaling Isometric Tile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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