Good point.
This is in the onStartScreen Method
[java]
Element cursorElement = screen.findElementByName(“Cursor”);
//cursorElement.hide();
CursorMoveListener cursor = new CursorMoveListener(cursorElement, settings);
float startX = inputManager.getCursorPosition().x;
float startY = settings.getHeight() - inputManager.getCursorPosition().y;
cursorElement.setConstraintX(new SizeValue((int) startX + "px"));
cursorElement.getParent().layoutElements();
cursorElement.setConstraintY(new SizeValue((int) startY + "px"));
cursorElement.getParent().layoutElements();
inputManager.addRawInputListener(cursor);
[/java]
And here’s the class’s own personal listener:
[java]
private class CursorMoveListener implements RawInputListener
{
private Element cursor;
private AppSettings settings;
private float x=0, y=0;
public CursorMoveListener()
{
}
public CursorMoveListener(Element cursor, AppSettings settings)
{
this.cursor = cursor;
this.settings = settings;
}
public void beginInput()
{
}
public void endInput()
{
}
public void onJoyAxisEvent(JoyAxisEvent evt)
{
float deadzone = inputManager.getAxisDeadZone();
System.out.println("Axis Deadzones: " + inputManager.getAxisDeadZone());
System.out.println("Moved Joystick");
if (evt.getAxis().getName().equalsIgnoreCase("x"))
{
System.out.println("X Value: " + evt.getValue());
if (evt.getValue() >= deadzone)
{
x += 5;
}
else if (evt.getValue() <= -deadzone)
{
x -= 5;
}
}
if (evt.getAxis().getName().equalsIgnoreCase("y"))
{
System.out.println("Y Value: " + evt.getValue());
if (evt.getValue() >= deadzone)
{
y += 10;
}
else if (evt.getValue() <= -deadzone)
{
y -= 10;
}
}
x = FastMath.clamp(x, 0, settings.getWidth() - 12);
y = FastMath.clamp(y, 0, settings.getHeight() - 19);
System.out.println(x + ", " + y);
cursor.setConstraintX(new SizeValue((int) x + "px"));
cursor.getParent().layoutElements();
cursor.setConstraintY(new SizeValue((int) y + "px"));
cursor.getParent().layoutElements();
fightButtonControl(fightButton.isClickable((int) x, (int) y), false);
}
public void onJoyButtonEvent(JoyButtonEvent evt)
{
}
public void onMouseMotionEvent(MouseMotionEvent evt)
{
System.out.println("Moved Mouse");
x = evt.getX();
y = settings.getHeight() - evt.getY();
System.out.println(x + ", " + y);
x = FastMath.clamp(x, 0, settings.getWidth() - 12);
y = FastMath.clamp(y, 0, settings.getHeight() - 19);
cursor.setConstraintX(new SizeValue((int) x + "px"));
cursor.getParent().layoutElements();
cursor.setConstraintY(new SizeValue((int) y + "px"));
cursor.getParent().layoutElements();
fightButtonControl(fightButton.isClickable((int) x, (int) y), false);
// trainingButtonControl(trainingButton.isClickable(x, y), wasClick);
// extrasButtonControl(extrasButton.isClickable(x, y), wasClick);
// optionsButtonControl(optionsButton.isClickable(x, y), wasClick);
}
public void onMouseButtonEvent(MouseButtonEvent evt)
{
x = evt.getX();
y = settings.getHeight() - evt.getY();
System.out.println("Clicked Mouse");
System.out.println(fightButton.isClickable((int) x, (int) y));
fightButtonControl(fightButton.isClickable((int) x, (int) y), true);
}
public void onKeyEvent(KeyInputEvent evt)
{
if (evt.getKeyCode() == KeyInput.KEY_A)
{
x -= 10;
}
if (evt.getKeyCode() == KeyInput.KEY_D)
{
x += 10;
}
if (evt.getKeyCode() == KeyInput.KEY_W)
{
y -= 10;
}
if (evt.getKeyCode() == KeyInput.KEY_S)
{
y += 10;
}
x = FastMath.clamp(x, 0, settings.getWidth() - 12);
y = FastMath.clamp(y, 0, settings.getHeight() - 19);
cursor.setConstraintX(new SizeValue((int) x + "px"));
cursor.getParent().layoutElements();
cursor.setConstraintY(new SizeValue((int) y + "px"));
cursor.getParent().layoutElements();
fightButtonControl(fightButton.isClickable((int) x, (int) y), false);
}
public void onTouchEvent(TouchEvent evt)
{
}
};[/java]
I don’t believe any other parts of the code are necessary to know for this, but let me know if you think you need to see more.