Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
491d937
background
JDLiang100 Feb 14, 2023
47dfe2b
Added a zombie character
JDLiang100 Feb 14, 2023
694b005
object moves
JDLiang100 Feb 14, 2023
cf7c02a
deleted the .py file and set up the .rst file
JDLiang100 Feb 18, 2023
ab61c8c
trial
JDLiang100 Feb 18, 2023
033dd77
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
8851483
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
4d88f11
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
c4c7f52
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
85b5203
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
0a4cb8f
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
a3d592f
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
f7b2b96
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
2dd834e
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
bd693b8
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
501cf55
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
5aaeb0b
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
a2422d8
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
a5d2297
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
d501ac2
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
d56ed9f
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
e1cf18e
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
cea4253
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
9e33610
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
5ebd12f
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
5df0b72
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
c849727
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
cb875ea
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
03bba81
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
db9def6
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
da68826
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
0123aa0
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
3b109ce
Update joystick_controller.rst
JDLiang100 Feb 18, 2023
f700bec
Update joystick_controller.rst
michellejtan Feb 18, 2023
784f8b1
Update joystick_controller.rst
michellejtan Feb 18, 2023
a632625
Update joystick_controller.rst
michellejtan Feb 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arcade/examples/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.joys = arcade.get_joysticks()#gets the joystick
80 changes: 80 additions & 0 deletions doc/example_code/how_to_examples/joystick_controller.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
.. _example-code:

How to get connected controllers
===================
We can get a list of connected controllers by using :code:`arcade.get_joysticks()`.

.. code-block:: python

joysticks = arcade.get_joysticks()
if joysticks:
self.joystick = joysticks[0]
self.joystick.open()
else:
print("There are no joysticks.")
self.joystick = None

Joystick Values
================
The joystick values can be obtained by using :code:`self.joystick.x` and :code:`self.joystick.y`. This can be used to update the current positon of an object.
def update(self, delta_time):

.. code-block:: python

# Update the position according to the game controller
if self.joystick:
print(self.joystick.x, self.joystick.y)

self.object.change_x = self.joystick.x
self.object.change_y = -self.joystick.y

How to use buttons
===================
How to use hatHow to use ranged triggers (like for acceleration)
=================================================================
Different types of controllers
==============================
How the (-1.0 to 1.0) range works
==================================
Deadzone
========
A centered joystick might have a value not at 0, but at 0.0001 or some small number. This will make for a small “drift” on a person’s character. We often counteract this by having a “dead zone” where if the number is below a certain value, we just assume it is zero to eliminate the drift.

How we take care of the dead zone:

After

.. code-block:: console

import arcade

add the following line:

.. code-block:: console

DEAD_ZONE = 0.02


and adding the following code to the :code:`update`:

.. code-block:: python

def update(self, delta_time):

# Update the position according to the game controller
if self.joystick:

# Set a "dead zone" to prevent drive from a centered joystick
if abs(self.joystick.x) < DEAD_ZONE:
self.object.change_x = 0
else:
self.object.change_x = self.joystick.x * MOVEMENT_SPEED

# Set a "dead zone" to prevent drive from a centered joystick
if abs(self.joystick.y) < DEAD_ZONE:
self.object.change_y = 0
else:
self.object.change_y = -self.joystick.y * MOVEMENT_SPEED

How-To Example Code
===================