Created
November 3, 2015 15:56
-
-
Save loudoweb/be0bd62984c804a55ca7 to your computer and use it in GitHub Desktop.
Fix tile trick to avoid border artifacts between tiles. #haxe #openfl
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; | |
/** | |
* 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