GMS2 一個xbox手柄被識別為2個手柄


參照gamemaker studio2的教程Adding Gamepad Support - Code進行學習時遇到了問題。
教程中的代碼功能是當識別接入了手柄時,會創建一個player實例。而當我把自己的xbox one s手柄連接到電腦時,游戲中生成了兩個player實例。也就是說,一個xbox手柄被識別為了兩個手柄。經過debug,被識別出的兩個虛擬手柄中有一個不能接收手柄的所有輸入,比如十字鍵的輸入。

閱讀gms2的解釋

When a gamepad is plugged in to the device running the game, it is assigned a "slot" value which is its pad_index. This index value is then used in all further gamepad functions to identify it, and on most platforms pads are indexed from 0, so the first pad connected will be in slot 0, and the second in slot 1 etc... Be aware that on Android you may find that the first gamepad connected is actually placed in slot 1, as the OS reserves slot 0 for general bluetooth connections. On Windows, gamepads which use DirectInput will be detected in slots 0 - 3 (Xbox 360/Xbox One pads, most PC pads) and Xinput devices would be detected in slots 4 - 11 (PS DualShock 4, many newer PC pads).

又經過代碼測試,可知接入的xbox手柄被識別為接入了slot 0和slot 4,而slot 0是功能完善的。於是我修改代碼,僅識別pad_index在0-3之間的手柄。

// Get the pad index value from the async_load map
	var pad = async_load[? "pad_index"];
	// Set the "deadzone" for the axis
	gamepad_set_axis_deadzone(pad, 0.5);
	// Set the "threshold" for the triggers
	gamepad_set_button_threshold(pad, 0.1);
	// Check to see if an instance is associated with this pad index
	// 僅當手柄索引為0-3時有效
	if !(instance_exists(player[pad])) && pad>=0 && pad<=3
	{
		// Create a player object and assign it a pad number
		var _xx = 64 + random(room_width - 128);
		var _yy = 64 + random(room_height - 128);
		player[pad] = instance_create_layer(_xx, _yy, "instances", obj_Player);
		with (player[pad])
		{
			image_index = instance_number(object_index) - 1;
			pad_num = pad;
		}
	}

之后,對於接入的xbox手柄便不會出現bug。但我想到,dualshock4手柄在slot 4- 11,這樣不就不能使用ds4手柄了嗎?
於是我借來了同學的ds4手柄進行測試,果然在上面的代碼情況下ds4無法被識別。
解決方案是使用神器DS4Windows,它可以將ds4手柄偽裝成xbox手柄,這一功能就解決了我們的問題。
參照科技:如何將DualShock 4控制器連接到PC對DS4Windows進行安裝使用即可。
DS4Windows還可以讓ds4的觸控板變成可以操縱鼠標的觸摸屏,而且可以用RGB值修改呼吸燈的顏色,實在是太贊了!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM