Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options to select a single axis for the joystick #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion joy.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ var JoyStick = (function(container, parameters)
internalStrokeColor = (typeof parameters.internalStrokeColor === "undefined" ? "#003300" : parameters.internalStrokeColor),
externalLineWidth = (typeof parameters.externalLineWidth === "undefined" ? 2 : parameters.externalLineWidth),
externalStrokeColor = (typeof parameters.externalStrokeColor === "undefined" ? "#008000" : parameters.externalStrokeColor),
autoReturnToCenter = (typeof parameters.autoReturnToCenter === "undefined" ? true : parameters.autoReturnToCenter);
autoReturnToCenter = (typeof parameters.autoReturnToCenter === "undefined" ? true : parameters.autoReturnToCenter),
axis = (typeof parameters.axis === "undefined" ? false : parameters.axis);

// Create Canvas element and add it in the Container object
var objContainer = document.getElementById(container);
Expand Down Expand Up @@ -176,6 +177,11 @@ var JoyStick = (function(container, parameters)
movedX -= canvas.offsetParent.offsetLeft;
movedY -= canvas.offsetParent.offsetTop;
}
if(axis)
if(axis === 'y')
movedX = centerX;
else if(axis === 'x')
movedY = centerY;
// Delete canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// Redraw object
Expand Down Expand Up @@ -226,6 +232,11 @@ var JoyStick = (function(container, parameters)
movedX -= canvas.offsetParent.offsetLeft;
movedY -= canvas.offsetParent.offsetTop;
}
if(axis)
if(axis === 'y')
movedX = centerX;
else if(axis === 'x')
movedY = centerY;
// Delete canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// Redraw object
Expand Down