Last active
July 30, 2026 01:17
-
-
Save serialhex/1bd3496b01f6e8abd5da06caa38f8ff1 to your computer and use it in GitHub Desktop.
Multi-controller Errors Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Main | |
| @initialized = false | |
| # One-time setup that creates a Player for each connected gamepad. | |
| def initialize_connected_controllers | |
| return if @initialized | |
| @player = [] | |
| args.inputs.controllers.each_with_index do |c, i| | |
| if c.connected || c.active | |
| @player[i] = {x: 0, y: 0, w: 80, h: 80, path: "sprites/square/blue.png"} | |
| @initialized = true | |
| end | |
| end | |
| puts "Initalized: #{@players}" if @players | |
| end | |
| def tick | |
| initialize_connected_controllers | |
| args.inputs.controllers.each_with_index do |c, i| | |
| if c.connected | |
| speed_scale = 10.0 | |
| @player[i].x += args.inputs.controllers[i].left_analog_x_perc * speed_scale | |
| @player[i].y += args.inputs.controllers[i].left_analog_y_perc * speed_scale | |
| end | |
| end | |
| args.outputs.sprites << @player | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment