From ac9c50f2acb0dc90c7ca30c5a448083b9fe44fde Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 12 Feb 2016 04:11:51 -0500 Subject: [PATCH] v0.3.4a: re-added align methods pt.1 I realize that aligning to pixel values is important, removing these in 0.3.1d was a mistake. However, previously they were aligning to integer values. not just real pixels. Hopefully this will result in proper alignment without incorrect spacing. --- .../scenes/PixelScene.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java index fbcbdfe3c..9942895eb 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java @@ -37,6 +37,7 @@ import com.watabou.noosa.Game; import com.watabou.noosa.RenderedText; import com.watabou.noosa.RenderedTextMultiline; import com.watabou.noosa.Scene; +import com.watabou.noosa.Visual; import com.watabou.utils.BitmapCache; import javax.microedition.khronos.opengles.GL10; @@ -200,7 +201,7 @@ public class PixelScene extends Scene { int zoom = Math.min(defaultZoom, 5); RenderedText result = new RenderedText( text, size*zoom); //adding 0.001f helps with smoothness on lower resolution devices. - result.scale.set(1/(float)zoom + .001f); + result.scale.set(1/(float)zoom); return result; } @@ -211,10 +212,30 @@ public class PixelScene extends Scene { public static RenderedTextMultiline renderMultiline( String text, int size ){ int zoom = Math.min(defaultZoom, 5); RenderedTextMultiline result = new RenderedTextMultiline( text, size*zoom); - result.zoom(1/(float)zoom + .001f); + result.zoom(1/(float)zoom); return result; } + /** + * These three methods align UI elements to device pixels. + * e.g. if we have a scale of 3x then valid positions are #.0, #.33, #.67 + */ + + public static float align( Camera camera, float pos ) { + return Math.round(pos * camera.zoom) / camera.zoom; + } + + // This one should be used for UI elements + public static float align( float pos ) { + return Math.round(pos * defaultZoom) / (float)defaultZoom; + } + + public static void align( Visual v ) { + Camera c = v.camera(); + v.x = align( c, v.x ); + v.y = align( c, v.y ); + } + public static boolean noFade = false; protected void fadeIn() { if (noFade) {