Do not cover the piece with the finger on mobile

This commit is contained in:
Lonami Exo 2017-02-05 15:46:07 +01:00
parent 206b93968f
commit d31991a7af
2 changed files with 13 additions and 2 deletions

View file

@ -1,5 +1,6 @@
package io.github.lonamiwebs.klooni; package io.github.lonamiwebs.klooni;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Game; import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
@ -18,12 +19,15 @@ public class Klooni extends Game {
public static Theme theme; public static Theme theme;
public Skin skin; public Skin skin;
public static boolean onDesktop;
//endregion //endregion
//region Creation //region Creation
@Override @Override
public void create() { public void create() {
onDesktop = Gdx.app.getType().equals(Application.ApplicationType.Desktop);
prefs = Gdx.app.getPreferences("io.github.lonamiwebs.klooni.game"); prefs = Gdx.app.getPreferences("io.github.lonamiwebs.klooni.game");
// TODO Better way to have this skin somewhere // TODO Better way to have this skin somewhere

View file

@ -186,8 +186,15 @@ public class PieceHolder {
Gdx.input.getX(), Gdx.input.getX(),
Gdx.graphics.getHeight() - Gdx.input.getY()); // Y axis is inverted Gdx.graphics.getHeight() - Gdx.input.getY()); // Y axis is inverted
// Center the new piece position if (Klooni.onDesktop) {
mouse.sub(piece.getRectangle().width / 2, piece.getRectangle().height / 2); // Center the piece to the mouse
mouse.sub(piece.getRectangle().width * 0.5f, piece.getRectangle().height * 0.5f);
} else {
// Center the new piece position horizontally
// and push it up by it's a cell (arbitrary) vertically, thus
// avoiding to cover it with the finger (issue on Android devices)
mouse.sub(piece.getRectangle().width * 0.5f, -pickedCellSize);
}
piece.pos.lerp(mouse, 0.4f); piece.pos.lerp(mouse, 0.4f);
piece.cellSize = Interpolation.linear.apply(piece.cellSize, pickedCellSize, 0.4f); piece.cellSize = Interpolation.linear.apply(piece.cellSize, pickedCellSize, 0.4f);