Android GamePad vs. Desktop (Assertions)

Baker,

Back when I was using SDL 2.0.4 I found joystick buttons were giving different values (sometimes very odd / random ones) under Android compared to Windows, which might be the problem. Often the button index will be +20 on Android, so I hacked a fix that would just -20 if button value was >20, but it didn’t fix everything because it wasn’t consistent across all the different controllers. There was no pattern to the oddness. Now I have it all working in SDL 2.0.8 I haven’t tested, but I’m guessing it’s the same. I’ll also try slokuen’s solution when I get time (what change you make, slokuen?).

Actually, here are my notes on the button indexes:

Gamecube PC:
A = 1
B = 2
X = 0
Y = 3
Start = 9
UDLR = 12, 14, 15, 13
L-shoulder = 4
R-shoulder = 5
Z = 7

Gamecube Android:
L-shoulder = 24
R-shoulder = 25
UDLR = 32, 34, 35, 33
Start = 29
buttons = 20-23
Z = 27

impact PC:
buttons = 0 - 3

impact Android:
buttons = 0 - 2 & 17 ?!

Vinyson CP:
L-shoulder = 4 & 6
R-shoulder = 5 & 7
buttons = 0 - 3
L-stick = 10
R-stick = 11
Start = 8 & 9

Vinyson Android:
L-shoulder = 24 & 26
R-shoulder = 25 & 27
L-stick = 30
R-stick = 31
buttons = 20 - 23
Start = 28 & 29

XBOX PC:
UDLR 11, 12, 13, 14
L-shoulder = 9
R-shoulder = 10

XBOX Android: n/a

Sega PC:
L-shoulder = 4
R-shoulder = 5
buttons = 0 - 3

Sega Android:
buttons = 20 - 23
L-shoulder = 24
R-shoulder = 25

When using the joystick interface it’s also safe 95% of the time to assume that axis 0 is X and axis 1 is Y; any axis beyond that are pretty random across controller designs. I think it’s better to make this assumption rather than not support unmapped controllers at all. Best solution is to use SDL’s controller mapping, and then backup with an assumed mapping for plain joysticks.

Back to portrait / landscape. It’s really easy. Look at AndroidManifest.xml:

   <activity
        android:screenOrientation="landscape"

It’s that easy.