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

Apple TV gamepad B button always exits app after app has exited once with exitOnMenuPress=true #657

Open
8bitmatt opened this issue Mar 14, 2017 · 0 comments

Comments

@8bitmatt
Copy link

8bitmatt commented Mar 14, 2017

Below is a slightly modified version of the gamepad test script (used to verify this bug).
On-screen button fill color is green when exitOnMenuPress = true, and red when exitOnMenuPress = false. (Note: testing with SteelSeries Nimbus controller)

Steps to reproduce:

  1. launch app
  2. press R1 (sets exitOnMenuPress = false)
  3. press Menu button (does not exit as it should)
  4. press B button (does not exit as it should)
  5. press L1 (exitOnMenuPress = true)
  6. press Menu button or B button (exits app)
  7. press A button (to re-enter app)
  8. press R1 (exitOnMenuPress = false)
  9. press Menu button (does not exit as it should)
  10. press B button (app exits! From this point on, no matter what exitOnMenuPress is set to the B button will exit)
canvas.width = window.innerWidth * window.devicePixelRatio;
canvas.height = window.innerHeight * window.devicePixelRatio;
canvas.style.width = window.innerWidth + "px";
canvas.style.height = window.innerHeight + "px";

var ctx = canvas.getContext("2d");

var scale = canvas.width / 1280;
ctx.scale(scale, scale);
ctx.font = '32px Helvetica';
ctx.fillStyle = '#fff';
ctx.strokeStyle = '#fff';
ctx.lineWidth = 2;

var drawButton = function(button, x, y, action, gamepad) {
	ctx.fillRect(x - 24, y + 24 - 48 * button.value, 48, 48 * button.value );

	
	if (button.pressed && action === 'enable') {
		gamepad.exitOnMenuPress = true;
	} else if (button.pressed && action === 'disable') {
		gamepad.exitOnMenuPress = false;
	}
	
	ctx.strokeStyle = button.pressed ? '#0f0' : '#ccc';
	ctx.strokeRect(x - 24, y - 24, 48, 48);
	ctx.strokeStyle = '#fff';
};

var drawAnalogStick = function( axisX, axisY, x, y ) {
	ctx.beginPath();
	ctx.arc(x, y, 64, 0, 2*Math.PI);
	ctx.stroke();
	
	ctx.beginPath();
	ctx.arc(x + axisX*48, y + axisY*48, 16, 0, 2*Math.PI);
	ctx.fill();
};

setInterval(function(){
	ctx.clearRect(0, 0, canvas.width/scale, canvas.height/scale);


	var gamepads = navigator.getGamepads();
	var gamepad = gamepads[1] || gamepads[0];


	if (gamepad.exitOnMenuPress) {
		ctx.fillStyle = "green";
	} else {
		ctx.fillStyle = "red";
	}


	if( !gamepad ) {
	ctx.fillText('No Gamepads connected', 32, 32);
	return;
	}

	ctx.fillText('Using Gamepad: #' + gamepad.index + ' ('+gamepad.id+')', 32, 32);


	// Button Mappings according to http://www.w3.org/TR/gamepad/#remapping

	drawButton(gamepad.buttons[0], 928, 354); // A
	drawButton(gamepad.buttons[1], 994, 288); // B
	drawButton(gamepad.buttons[2], 862, 288); // X
	drawButton(gamepad.buttons[3], 928, 224); // Y

	drawButton(gamepad.buttons[4], 412, 96, 'enable', gamepad); // L1
	drawButton(gamepad.buttons[5], 868, 96, 'disable', gamepad); // R1
	drawButton(gamepad.buttons[6], 288, 96); // L2
	drawButton(gamepad.buttons[7], 994, 96); // R2

	drawButton(gamepad.buttons[12], 352, 224); // Up
	drawButton(gamepad.buttons[13], 352, 354); // Down
	drawButton(gamepad.buttons[14], 288, 288); // Left
	drawButton(gamepad.buttons[15], 416, 288); // Right

	drawButton(gamepad.buttons[16], 640, 196); // Menu

	drawAnalogStick(gamepad.axes[0], gamepad.axes[1], 540, 416); // left stick
	drawAnalogStick(gamepad.axes[2], gamepad.axes[3], 736, 416); // right stick


}, 16);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant