private TouchpadStyle style;\r
boolean touched;\r
private float deadzoneRadius;\r
- private final Circle padBounds = new Circle(0, 0, 0);\r
+ private final Circle knobBounds = new Circle(0, 0, 0);\r
private final Circle touchBounds = new Circle(0, 0, 0);\r
private final Circle deadzoneBounds = new Circle(0, 0, 0);\r
private final Vector2 knobPosition = new Vector2();\r
float oldPositionY = knobPosition.y;\r
float oldPercentX = knobPercent.x;\r
float oldPercentY = knobPercent.y;\r
- knobPosition.set(getWidth() / 2f, getHeight() / 2f);\r
+ float centerX = knobBounds.x;\r
+ float centerY = knobBounds.y;\r
+ knobPosition.set(centerX, centerY);\r
knobPercent.set(0f, 0f);\r
if (!isTouchUp) {\r
if (!deadzoneBounds.contains(x, y)) {\r
- knobPercent.set(x - padBounds.x, y - padBounds.y).nor();\r
- if (padBounds.contains(x, y)) {\r
+ knobPercent.set((x - centerX) / knobBounds.radius, (y - centerY) / knobBounds.radius);\r
+ float length = knobPercent.len();\r
+ if (length > 1) knobPercent.mul(1 / length);\r
+ if (knobBounds.contains(x, y)) {\r
knobPosition.set(x, y);\r
} else {\r
- knobPosition.set(knobPercent).mul(padBounds.radius).add(padBounds.x, padBounds.y);\r
+ knobPosition.set(knobPercent).nor().mul(knobBounds.radius).add(knobBounds.x, knobBounds.y);\r
}\r
}\r
}\r
float radius = Math.min(halfWidth, halfHeight);\r
touchBounds.set(halfWidth, halfHeight, radius);\r
if (style.knob != null) radius -= Math.max(style.knob.getMinWidth(), style.knob.getMinHeight()) / 2;\r
- padBounds.set(halfWidth, halfHeight, radius);\r
+ knobBounds.set(halfWidth, halfHeight, radius);\r
deadzoneBounds.set(halfWidth, halfHeight, deadzoneRadius);\r
// Recalc pad values and knob position\r
knobPosition.set(halfWidth, halfHeight);\r
\r
public class TouchpadTest extends GdxTest {\r
Stage stage;\r
+ Touchpad touchpad;\r
\r
public void create () {\r
stage = new Stage();\r
\r
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));\r
\r
- Touchpad touchpad = new Touchpad(20, skin);\r
+ touchpad = new Touchpad(20, skin);\r
touchpad.setBounds(15, 15, 100, 100);\r
stage.addActor(touchpad);\r
}\r
\r
public void render () {\r
- // System.out.println(meow.getValue());\r
+ //System.out.println(touchpad.getKnobPercentX() + " " + touchpad.getKnobPercentY());\r
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
stage.act(Gdx.graphics.getDeltaTime());\r
stage.draw();\r