Created
August 2, 2014 05:53
-
-
Save tommyettinger/38e0fa337f5804b67bde to your computer and use it in GitHub Desktop.
Viewport that should only stretch in integer increments, but doesn't
This file contains hidden or 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 commanders.unite.utils | |
import com.badlogic.gdx.graphics.Camera; | |
import com.badlogic.gdx.graphics.OrthographicCamera; | |
import com.badlogic.gdx.utils.viewport.Viewport | |
; | |
/** | |
* Created by Tommy Ettinger on 8/1/2014. | |
*/ | |
class CustomViewport(var minWorldWidth:Float, | |
var minWorldHeight:Float, | |
var maxWorldWidth:Float = 1280f, | |
var maxWorldHeight:Float = 720f, | |
var cam:Camera = new OrthographicCamera()) extends Viewport | |
{ | |
camera = cam | |
override def update (screenWidth:Int, screenHeight:Int, centerCamera:Boolean) { | |
worldWidth = minWorldWidth | |
worldHeight = minWorldHeight | |
viewportWidth = (worldWidth * Math.floor(screenWidth / worldWidth)).toInt | |
viewportHeight = (worldHeight * Math.floor(screenHeight / worldHeight)).toInt | |
viewportX = (screenWidth - viewportWidth) / 2 | |
viewportY = (screenHeight - viewportHeight) / 2 | |
super.update(screenWidth, screenHeight, centerCamera) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment