Skip to content

Instantly share code, notes, and snippets.

Created November 3, 2015 15:56
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Fix tile trick to avoid border artifacts between tiles. #haxe #openfl
* Avoid holes or border artifacts between tiles.
* Sometimes the scale by 1.01 trick doesn't work, a greater value should be used. This method finds the correct value for you.
* If you use openfl_legacy, pack your atlas using reduceBorderArtifact option in TexturePacker. There is no need to use this option on openfl_next.
* You should update the scale of your tiles if your resize the screen during the game to always have the best scale value.
* @author loudo
class FixTile
public static var minFixScale:Float = 1.01;
public function new()
inline public static function getScale(tileSize:Int, stageScale:Float, tileScale:Float = 1):Float
if (stageScale * tileScale == 1)
return 1;//no need to fix the scale because there is no scale
var sizeOnScreen:Float = tileSize * stageScale * tileScale;
var bestSize:Int = Math.ceil(sizeOnScreen);
return Math.max(minFixScale, bestSize / sizeOnScreen);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment