diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java index b3285f327..6965e35ee 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/CellSelector.java @@ -22,6 +22,8 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; import com.shatteredpixel.shatteredpixeldungeon.DungeonTilemap; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; +import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.watabou.input.Touchscreen.Touch; import com.watabou.noosa.TouchArea; import com.watabou.utils.GameMath; @@ -55,6 +57,24 @@ public class CellSelector extends TouchArea { (int)touch.current.y ) ); } } + + private float zoom( float value ) { + + value = GameMath.gate( PixelScene.minZoom, value, PixelScene.maxZoom ); + ShatteredPixelDungeon.zoom((int) (value - PixelScene.defaultZoom)); + camera.zoom( value ); + + //Resets character sprite positions with the new camera zoom + //This is important as characters are centered on a 16x16 tile, but may have any sprite size + //This can lead to none-whole coordinate, which need to be aligned with the zoom + for (Char c : Actor.chars()){ + if (c.sprite != null && !c.sprite.isMoving){ + c.sprite.point(c.sprite.worldToCamera(c.pos)); + } + } + + return value; + } public void select( int cell ) { if (enabled && listener != null && cell != -1) { @@ -103,9 +123,7 @@ public class CellSelector extends TouchArea { pinching = false; - int zoom = Math.round( camera.zoom ); - camera.zoom( zoom ); - ShatteredPixelDungeon.zoom((int) (zoom - PixelScene.defaultZoom)); + zoom(Math.round( camera.zoom )); dragging = true; if (t == touch) { @@ -163,9 +181,7 @@ public class CellSelector extends TouchArea { if (pinching){ pinching = false; - int zoom = Math.round( camera.zoom ); - camera.zoom( zoom ); - ShatteredPixelDungeon.zoom((int) (zoom - PixelScene.defaultZoom)); + zoom( Math.round( camera.zoom ) ); } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java b/src/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java index c3ce8cb87..ee06c9faf 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java @@ -37,6 +37,8 @@ import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfInvisibili import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; +import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; +import com.watabou.noosa.Camera; import com.watabou.noosa.Game; import com.watabou.noosa.MovieClip; import com.watabou.noosa.Visual; @@ -117,8 +119,8 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip final int csize = DungeonTilemap.SIZE; return new PointF( - ((cell % Level.WIDTH) + 0.5f) * csize - width * 0.5f, - ((cell / Level.WIDTH) + 1.0f) * csize - height + PixelScene.align(Camera.main, ((cell % Level.WIDTH) + 0.5f) * csize - width * 0.5f), + PixelScene.align(Camera.main, ((cell / Level.WIDTH) + 1.0f) * csize - height) ); }