SnakeGo : Scaling Screen on Stage
剛才使用LIBGDX的Stage時, 發現1.0.1跟0.99的一個變更 -- Stage內置Camera和Viewport(好用的ScalingViewport類). 如此這樣, 那放縮屏幕更方便了...
@Override public void resize(int width, int height) { Vector2 size = Scaling.fit.apply(CommonConsts.Screen.WIDTH, CommonConsts.Screen.HEIGHT, width, height); this.getViewport().update((int)size.x, (int)size.y, true);
// Vector2 screenScaling = new Vector2((size.x / CommonConsts.Screen.WIDTH), (size.y / CommonConsts.Screen.HEIGHT)); // this.getRoot().setScale(screenScaling.x, screenScaling.y); }
Stage內置的Camera和Viewport把'原點'放在左下角, 而不是常使用的'居中', 另外這個還有個問題, 當屏幕縮放時, Viewport也不是一般習慣'居中'顯示, 也是是靠左下. 我簡單查看了下相應的Viewport類, 沒有發現如何設置這個偏移量. 只是SnakeGo'豎屏'模式在N4上正好'鋪滿', 這個問題再說吧. 如果需要, 能預估最麻煩的就是重載ScalingViewport類了.
代碼中, 后面注釋掉的兩句是用于等比例放縮圖形的, 還沒認真算過, 似乎不需要也可以的, 需要再看看Viewport類..
posted on 2014-05-19 23:11 codejie 閱讀(1571) 評論(0) 編輯 收藏 引用 所屬分類: I;P