浏览代码

Improve joystick visualisation in gamepad example (#2390)

The joystick range is a float from -1 through +1. Casting this to int
yields only three possible values: -1, 0, and 1. This gives a
misleading joystick placement in the demo.

By casting to int after the multiplication, the demo reveals the
analog feel of the joystick.
pull/2391/head
Kristian Lein-Mathisen 3 年前
committed by GitHub
父节点
当前提交
ec7250ca54
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. +4
    -4
      examples/core/core_input_gamepad.c

+ 4
- 4
examples/core/core_input_gamepad.c 查看文件

@ -140,14 +140,14 @@ int main(void)
// Draw axis: left joystick // Draw axis: left joystick
DrawCircle(319, 255, 35, BLACK); DrawCircle(319, 255, 35, BLACK);
DrawCircle(319, 255, 31, LIGHTGRAY); DrawCircle(319, 255, 31, LIGHTGRAY);
DrawCircle(319 + (p">(int)GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) * 20),
255 + (p">(int)GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y) * 20), 25, BLACK);
DrawCircle(319 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) * 20),
255 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y) * 20), 25, BLACK);
// Draw axis: right joystick // Draw axis: right joystick
DrawCircle(475, 255, 35, BLACK); DrawCircle(475, 255, 35, BLACK);
DrawCircle(475, 255, 31, LIGHTGRAY); DrawCircle(475, 255, 31, LIGHTGRAY);
DrawCircle(475 + (p">(int)GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X)*20),
255 + (p">(int)GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y)*20), 25, BLACK);
DrawCircle(475 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X) * 20),
255 + (int)(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y) * 20), 25, BLACK);
// Draw axis: left-right triggers // Draw axis: left-right triggers
DrawRectangle(169, 48, 15, 70, GRAY); DrawRectangle(169, 48, 15, 70, GRAY);

正在加载...
取消
保存