joystick

Algorithm of the joystick on the touchable screen

。_饼干妹妹 提交于 2019-12-03 15:33:34
I would like to simulate an analog joystick on the touchable screen like this picture. When the center of the stick area is set to (cx, cy), how should I calculate X-direction ratio and Y-direction ratio(-1.0~1.0) from the touched position(tx, ty)? The x direction ratio is (tx-cx)/r, where r is the radius magnitude of the circle. Similarly, the y direction ratio is (ty-cy)/r. I am assuming a right-handed cartesian coordinate with x axis in the direction of the right of the picture. Otherwise, you may need to multiply a (-1) to adjust the direction. 来源: https://stackoverflow.com/questions

Unity自定义摇杆实现

烈酒焚心 提交于 2019-12-03 14:09:01
Unity自定义摇杆 Unity利用自带的UGUI进行制作摇杆,并且利用事件来自定义注册具体的实现。 摇杆只要组成就是一个背景图片和一个中心的用来触摸的圆。 具体需要哪种事件,根据自己的逻辑来判断实现,不一定所有都需要。 文末会附演示工程文件。 摇杆的事件代码 public class JoyStick : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler, IEndDragHandler { public float outerCircleRadius = 50 ; //可以拖动的最大距离 Transform thumb; //触摸球 Vector2 thumb_start; Vector2 direction; //滑动方向 public Action<Vector2> onJoystickDownEvent; // 按下事件 public Action onJoystickUpEvent; // 抬起事件 public Action<Vector2> onJoystickDragEvent; // 滑动事件 public Action<Vector2> onJoystickDragEndEvent; // 滑动结束事件 void Start() { thumb = transform

Joystick support in Java

非 Y 不嫁゛ 提交于 2019-12-03 13:30:16
Are there any libraries out there allowing access to joystick input in Java? The minimum requirements would be for it to work under Windows, to be able to detect all connected joysticks and to handle axes and buttons. Try JInput https://github.com/jinput/jinput It works even on Linux :) 来源: https://stackoverflow.com/questions/10302764/joystick-support-in-java

joyGetPosEx returns 165 in C#

人盡茶涼 提交于 2019-12-02 12:26:22
问题 I tried to read out the data from my JoyStick in C# which is working fine as long as i do it with jeyGetPos. But I need to use joyGetPosEx because it delivers more date like the rotation of the Joystick which I need. class JoyStick { JOYINFO pji; JOYINFOEX pjiex; MMRESULT mmresult; public JoyStick() { pji = new JOYINFO(); pjiex = new JOYINFOEX(); } [StructLayout(LayoutKind.Sequential)] public struct JOYINFO { public uint wYpos; public uint wZpos; public uint wButtons; } [StructLayout

joyGetPosEx returns 165 in C#

冷暖自知 提交于 2019-12-02 04:07:51
I tried to read out the data from my JoyStick in C# which is working fine as long as i do it with jeyGetPos. But I need to use joyGetPosEx because it delivers more date like the rotation of the Joystick which I need. class JoyStick { JOYINFO pji; JOYINFOEX pjiex; MMRESULT mmresult; public JoyStick() { pji = new JOYINFO(); pjiex = new JOYINFOEX(); } [StructLayout(LayoutKind.Sequential)] public struct JOYINFO { public uint wYpos; public uint wZpos; public uint wButtons; } [StructLayout(LayoutKind.Sequential)] public struct JOYINFOEX { public uint dwSize; public uint dwFlags; public uint dwXpos;

Pygame headless setup

拜拜、爱过 提交于 2019-12-01 17:02:22
问题 This question was migrated from Raspberry Pi Stack Exchange because it can be answered on Stack Overflow. Migrated 4 years ago . I am using pygame's joystick api to use a joystick with my project on a headless system, but pygame requires a "screen" so I have setup a dummy video system to over come this. It worked fine but now all of a sudden it gives me this error: Traceback (most recent call last): File "compact.py", line 10, in <module> screen = display.set_mode((1, 1)) pygame.error: Unable

Pygame headless setup

限于喜欢 提交于 2019-12-01 16:55:10
I am using pygame's joystick api to use a joystick with my project on a headless system, but pygame requires a "screen" so I have setup a dummy video system to over come this. It worked fine but now all of a sudden it gives me this error: Traceback (most recent call last): File "compact.py", line 10, in <module> screen = display.set_mode((1, 1)) pygame.error: Unable to open a console terminal Here is what I have as the headless setup that is supposed to over come this issue. from pygame import * import os import RPi.GPIO as GPIO os.environ["SDL_VIDEODRIVER"] = "dummy" screen = display.set_mode

Android onscreen joystick issues

若如初见. 提交于 2019-11-30 22:31:00
So I'm trying to build a game with an on-screen joystick that moves a bitmap around the screen. But when I hold the joystick down in any direction and keep it there, the bitmap will stop moving as well. Its only when I am moving the joystick does the bitmap move. Basically I want to be able to hold down the joystick in say the left position and have the bitmap move left until I let go. Everything else in the code works. Any suggestions? public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) _dragging = true; else if (event.getAction() ==

Android onscreen joystick issues

自作多情 提交于 2019-11-30 17:20:25
问题 So I'm trying to build a game with an on-screen joystick that moves a bitmap around the screen. But when I hold the joystick down in any direction and keep it there, the bitmap will stop moving as well. Its only when I am moving the joystick does the bitmap move. Basically I want to be able to hold down the joystick in say the left position and have the bitmap move left until I let go. Everything else in the code works. Any suggestions? public boolean onTouch(View v, MotionEvent event) { if

自定义虚拟摇杆组件让你一劳永逸

為{幸葍}努か 提交于 2019-11-29 06:25:26
最近在研究虚拟摇杆实现方式的时候,发现网上的教程的实现方式可移植性并不是特别好,于是我决定自己实现一个虚拟摇杆组件,保存到自己的组件库,方便以后用到的时候直接使用(关注公众号后台回复「虚拟摇杆组件」可获取该组件),下面正文开始。 实现思路: 为了实现高度可移植,定义了两个节点属性,用于绑定场景和玩家角色,另外添加 PlayerNodeSpeed 属性和 MaxR 属性用于控制玩家移动速度和摇杆节点的移动范围。 实现过程: 1.首先创建一个空节点 Rocker,下面挂载上虚拟摇杆的背景 rockerBg 和摇杆节点 joystick: 2.然后给创建好节点添加合适的虚拟摇杆资源,没有资源的小伙伴可以关注公众号后台回复「虚拟摇杆」获取多套美术资源: 3.之后编写脚本如下,代码中已经尽可能详细做好了备注,如果仍有不清楚的小伙伴可以后台私信我,看到后我会及时回复的: 1 // Rocker.js 2 3 cc.Class({ 4 extends: cc.Component, 5 6 properties: { 7 sceneNode: { // 场景节点 8 type: cc.Node, 9 default: null, 10 }, 11 12 playerNode: { // player节点 13 type: cc.Node, 14 default: null, 15 }, 16 17