Skip to content

Commit 1b51b85

Browse files
pvcravenPaul V Cravenclaude
authored
Remove outdated and duplicate names from the arcade namespace (#2965)
Removes AnimatedWalkingSprite (already documented as deprecated) and the FACE_* constants only it used, and get_game_controllers, a duplicate of get_joysticks whose name suggested it returned game controllers. Also drops the duplicate draw_lrbt_rectangle_filled/outline entries in arcade.__all__. Co-authored-by: Paul V Craven <paul.craven@optimizley.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 35c607b commit 1b51b85

9 files changed

Lines changed: 13 additions & 304 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ Arcade [PyPi Release History](https://pypi.org/project/arcade/#history) page.
5151
- Fixed `InputManager.parse()` raising `AttributeError`, so a saved input configuration couldn't be loaded.
5252

5353
### Breaking Changes
54+
- Removed outdated and duplicate names from the `arcade` namespace ([#2402](https://github.com/pythonarcade/arcade/issues/2402)):
55+
- `AnimatedWalkingSprite` and the `FACE_UP`, `FACE_DOWN`, `FACE_LEFT` and `FACE_RIGHT` constants it used. Its docs already called it deprecated and said to write your own sprite class instead. The `sprite_move_animation` example shows how.
56+
- `get_game_controllers()`, which did the same as `get_joysticks()`. Its name suggested it returned game controllers, but it returned joysticks. For game controllers, use `get_controllers()`.
57+
- `draw_lrbt_rectangle_filled` and `draw_lrbt_rectangle_outline` were each listed twice in `arcade.__all__`.
5458
- The default font is now Liberation Sans, which comes with Arcade, instead of whichever of Calibri and Arial the computer has ([#1135](https://github.com/pythonarcade/arcade/issues/1135)). Text looks the same on every computer. It applies to `Text`, `draw_text()`, `create_text_sprite()`, `TextPool`, and the GUI's `UILabel`, `UITextArea`, `UIInputText` and buttons (which still use Kenney Future first if you load the Kenney fonts). Liberation Sans has the same letter widths as Arial, so text on Windows, which used Calibri, is about 10% wider. For the old look, pass `font_name=("calibri", "arial")`.
5559
- The Liberation fonts load the first time one is used, so `font_name="Liberation Mono"` works without `load_liberation_fonts()`.
5660
- `UITextArea` and `UIInputText` accept font file paths and resource handles for `font_name`, like `Text`.
5761
- `arcade.load_tilemap()` and `TileMap` now give every layer's sprite list a spatial hash by default (`use_spatial_hash=True`) ([#2663](https://github.com/pythonarcade/arcade/issues/2663)). Forgetting it on a wall layer made collision checks against it much slower: 100 bullets checked against 2,000 wall tiles took 48 ms per frame without it and 0.6 ms with it. A hash makes moving a layer's sprites slower, so for a layer whose sprites move a lot, such as moving platforms, turn it off with `layer_options={"Moving Platforms": {"use_spatial_hash": False}}`, or for the whole map with `use_spatial_hash=False`.
5862
- `layer_options` now warns about option names it doesn't know, which it used to ignore. The performance tips page named the option `"use_spatial_hashing"`; it's `"use_spatial_hash"`.
59-
- `Sprite`, `BasicSprite`, `SpriteSolidColor`, `SpriteCircle`, `TextureAnimationSprite` and `AnimatedWalkingSprite` raise `TypeError` for keyword arguments they don't accept, instead of silently ignoring them. For example, `Sprite(path, hit_box_algorithm=...)` used to do nothing; set the hit box algorithm when loading the texture instead. `Sprite` now takes `visible` as a named argument.
60-
- `SpriteSolidColor`, `SpriteCircle`, `TextureAnimationSprite` and `AnimatedWalkingSprite` now pass extra keyword arguments on to `Sprite`, so arguments such as `angle` and `visible` work. They used to be dropped.
63+
- `Sprite`, `BasicSprite`, `SpriteSolidColor`, `SpriteCircle` and `TextureAnimationSprite` raise `TypeError` for keyword arguments they don't accept, instead of silently ignoring them. For example, `Sprite(path, hit_box_algorithm=...)` used to do nothing; set the hit box algorithm when loading the texture instead. `Sprite` now takes `visible` as a named argument.
64+
- `SpriteSolidColor`, `SpriteCircle` and `TextureAnimationSprite` now pass extra keyword arguments on to `Sprite`, so arguments such as `angle` and `visible` work. They used to be dropped.
6165
- This found arguments that had silently done nothing: tilemap image layers passed `filename` and `hit_box_algorithm`, animated tiles passed `path_or_texture`, and platform tutorial steps 19 and 20 passed `scaling` instead of `scale`, so their bullets were drawn at full size instead of 80%.
6266
- `arcade.math.get_angle_degrees()` now measures clockwise from straight up, like `Sprite.angle`: 0 is up, 90 is right, 180 is down and -90 is left. It used to measure clockwise from the right, which disagreed with `get_angle_radians()`, which already measured from up ([#2754](https://github.com/pythonarcade/arcade/issues/2754)). The two now always give the same angle in different units. A sprite whose image points up faces a point with `sprite.angle = get_angle_degrees(...)`. For the old value, subtract 90.
6367
- Fixed the `sprite_rotate_around_tank` example's corrected barrel, which sat 90 degrees off from the mouse, and updated `turn_and_move` for the new angles. `turn_and_move`'s sprite also now stops when moving straight along an axis, which it never did.
@@ -85,7 +89,7 @@ Arcade [PyPi Release History](https://pypi.org/project/arcade/#history) page.
8589
- Type checking with mypy and pyright now fails the CI check, like formatting and linting. Their existing errors are fixed.
8690
- Fixed code excerpts in the docs that highlighted or showed the wrong lines, because the example code had changed since their line numbers were set. This covers 62 excerpts: 48 in the platformer, pymunk platformer, menu, card game, compute shader, raycasting and shader toy glow tutorials, and 14 on example pages. Most now highlight the same code they were written for. Where the code was rewritten, they highlight the code that does the same job now.
8791
- Removed `arcade/experimental/perspective_parallax.py`, an unreferenced demo of `PerspectiveProjector` that didn't show a parallax effect. The `background_parallax` example shows parallax scrolling.
88-
- Sped up `import arcade` from about 2.7 to 0.9 seconds on Windows ([#1159](https://github.com/pythonarcade/arcade/issues/1159)). Most of the time went to pyglet looking for game controllers when imported. Arcade now imports the controller code the first time `get_controllers()`, `ControllerManager`, `get_joysticks()` or `get_game_controllers()` is used, so the wait happens then instead. Sound still loads at import, so playing the first sound doesn't pause the game.
92+
- Sped up `import arcade` from about 2.7 to 0.9 seconds on Windows ([#1159](https://github.com/pythonarcade/arcade/issues/1159)). Most of the time went to pyglet looking for game controllers when imported. Arcade now imports the controller code the first time `get_controllers()`, `ControllerManager` or `get_joysticks()` is used, so the wait happens then instead. Sound still loads at import, so playing the first sound doesn't pause the game.
8993
- Arcade's extra controller mappings now load at the same time. Code that calls `pyglet.input.get_controllers()` directly without using Arcade's controller functions first only gets pyglet's own mappings.
9094

9195
## 4.0.0.dev8

‎arcade/__init__.py‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def configure_logging(level: int | None = None):
141141
# Game controllers are imported on first use, because pyglet lists the
142142
# input devices when imported. See __getattr__ at the bottom of this file.
143143
if TYPE_CHECKING:
144-
from .joysticks import get_game_controllers
145144
from .joysticks import get_joysticks
146145
from .controller import ControllerManager
147146
from .controller import get_controllers
@@ -162,13 +161,8 @@ def configure_logging(level: int | None = None):
162161
from .sound import play_sound
163162
from .sound import stop_sound
164163

165-
from .sprite import FACE_DOWN
166-
from .sprite import FACE_LEFT
167-
from .sprite import FACE_RIGHT
168-
from .sprite import FACE_UP
169164
from .sprite import TextureAnimationSprite
170165
from .sprite import load_animated_gif
171-
from .sprite import AnimatedWalkingSprite
172166
from .sprite import TextureAnimation
173167
from .sprite import TextureKeyframe
174168
from .sprite import PyMunk
@@ -283,16 +277,11 @@ def configure_logging(level: int | None = None):
283277
"PSControllerButtons",
284278
"XBoxControllerButtons",
285279
"AStarBarrierList",
286-
"AnimatedWalkingSprite",
287280
"TextureAnimationSprite",
288281
"TextureAnimation",
289282
"TextureKeyframe",
290283
"ArcadeContext",
291284
"ControllerManager",
292-
"FACE_DOWN",
293-
"FACE_LEFT",
294-
"FACE_RIGHT",
295-
"FACE_UP",
296285
"MOUSE_BUTTON_LEFT",
297286
"MOUSE_BUTTON_MIDDLE",
298287
"MOUSE_BUTTON_RIGHT",
@@ -361,8 +350,6 @@ def configure_logging(level: int | None = None):
361350
"draw_line_strip",
362351
"draw_lines",
363352
"draw_lrbt_rectangle_filled",
364-
"draw_lrbt_rectangle_filled",
365-
"draw_lrbt_rectangle_outline",
366353
"draw_lrbt_rectangle_outline",
367354
"draw_parabola_filled",
368355
"draw_parabola_outline",
@@ -388,7 +375,6 @@ def configure_logging(level: int | None = None):
388375
"get_distance_between_sprites",
389376
"get_sprites_in_rect",
390377
"get_controllers",
391-
"get_game_controllers",
392378
"get_image",
393379
"get_joysticks",
394380
"get_pixel",
@@ -450,7 +436,6 @@ def configure_logging(level: int | None = None):
450436
if not headless:
451437
_LAZY_IMPORTS = {
452438
"get_joysticks": "joysticks",
453-
"get_game_controllers": "joysticks",
454439
"joysticks": "joysticks",
455440
"ControllerManager": "controller",
456441
"get_controllers": "controller",

‎arcade/joysticks.py‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import pyglet.input
22
from pyglet.input import Joystick
33

4-
__all__ = ["get_joysticks", "get_game_controllers"]
4+
__all__ = ["get_joysticks"]
55

66

77
def get_joysticks() -> list[Joystick]:
88
"""
9-
Get a list of all the game controllers
9+
Get a list of all the joysticks.
1010
11-
This is an alias of :func:`get_game_controllers`, which is better worded.
11+
These are pyglet :py:class:`~pyglet.input.Joystick` objects, which give
12+
raw access to the axes and buttons. For game controllers with named
13+
buttons and sticks, use :py:func:`arcade.get_controllers` instead.
1214
"""
1315
return pyglet.input.get_joysticks() # type: ignore # pending https://github.com/pyglet/pyglet/issues/842
14-
15-
16-
def get_game_controllers() -> list[Joystick]:
17-
"""
18-
Get a list of all the game controllers
19-
"""
20-
return get_joysticks()

‎arcade/sprite/__init__.py‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,8 @@
1111
TextureAnimationSprite,
1212
TextureAnimation,
1313
TextureKeyframe,
14-
AnimatedWalkingSprite,
1514
)
1615
from .colored import SpriteSolidColor, SpriteCircle
17-
from .enums import (
18-
FACE_LEFT,
19-
FACE_RIGHT,
20-
FACE_UP,
21-
FACE_DOWN,
22-
)
2316

2417

2518
def load_animated_gif(resource_name: str | Path) -> TextureAnimationSprite:
@@ -76,13 +69,8 @@ def load_animated_gif(resource_name: str | Path) -> TextureAnimationSprite:
7669
"TextureAnimationSprite",
7770
"TextureAnimation",
7871
"TextureKeyframe",
79-
"AnimatedWalkingSprite",
8072
"load_animated_gif",
8173
"SpriteSolidColor",
8274
"SpriteCircle",
83-
"FACE_LEFT",
84-
"FACE_RIGHT",
85-
"FACE_UP",
86-
"FACE_DOWN",
8775
"PymunkMixin",
8876
]

‎arcade/sprite/animated.py‎

Lines changed: 1 addition & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
import bisect
22
import logging
3-
import math
43

54
from arcade import Texture
6-
from arcade.types import Point2
7-
8-
from .enums import (
9-
FACE_DOWN,
10-
FACE_LEFT,
11-
FACE_RIGHT,
12-
FACE_UP,
13-
)
5+
146
from .sprite import Sprite
157

168
logger = logging.getLogger("arcade")
@@ -211,156 +203,3 @@ def update_animation(self, delta_time: float = 1 / 60, **kwargs) -> None:
211203
if index != self._current_keyframe_index:
212204
self._current_keyframe_index = index
213205
self.texture = keyframe.texture
214-
215-
216-
class AnimatedWalkingSprite(Sprite):
217-
"""
218-
Deprecated Sprite for platformer games that supports walking animations.
219-
Make sure to call update_animation after loading the animations so the
220-
initial texture can be set. Or manually set it.
221-
222-
It is highly recommended you create your own version of this class rather than
223-
try to use this pre-packaged one.
224-
225-
For an example, see this section of the platformer tutorial:
226-
:ref:`platformer_part_twelve`.
227-
228-
Args:
229-
scale:
230-
Initial scale of the sprite.
231-
center_x:
232-
Initial x position of the sprite.
233-
center_y:
234-
Initial y position of the sprite.
235-
**kwargs:
236-
Passed to :py:class:`~arcade.Sprite`, such as ``angle``, ``scale`` or ``visible``.
237-
"""
238-
239-
def __init__(
240-
self,
241-
scale: float | Point2 = 1.0,
242-
center_x: float = 0.0,
243-
center_y: float = 0.0,
244-
**kwargs,
245-
):
246-
super().__init__(
247-
None,
248-
scale=scale,
249-
center_x=center_x,
250-
center_y=center_y,
251-
**kwargs,
252-
)
253-
self.state = FACE_RIGHT
254-
self.stand_right_textures: list[Texture] = []
255-
self.stand_left_textures: list[Texture] = []
256-
self.walk_left_textures: list[Texture] = []
257-
self.walk_right_textures: list[Texture] = []
258-
self.walk_up_textures: list[Texture] = []
259-
self.walk_down_textures: list[Texture] = []
260-
self.cur_texture_index = 0
261-
self.texture_change_distance = 20
262-
self.last_texture_change_center_x: float = 0.0
263-
self.last_texture_change_center_y: float = 0.0
264-
265-
def update_animation(self, delta_time: float = 1 / 60) -> None:
266-
"""
267-
Logic for texture animation.
268-
269-
Args:
270-
delta_time: Time since last update.
271-
"""
272-
x1 = self.center_x
273-
x2 = self.last_texture_change_center_x
274-
y1 = self.center_y
275-
y2 = self.last_texture_change_center_y
276-
distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
277-
texture_list: list[Texture] = []
278-
279-
change_direction = False
280-
if (
281-
self.change_x > 0
282-
and self.change_y == 0
283-
and self.state != FACE_RIGHT
284-
and len(self.walk_right_textures) > 0
285-
):
286-
self.state = FACE_RIGHT
287-
change_direction = True
288-
elif (
289-
self.change_x < 0
290-
and self.change_y == 0
291-
and self.state != FACE_LEFT
292-
and len(self.walk_left_textures) > 0
293-
):
294-
self.state = FACE_LEFT
295-
change_direction = True
296-
elif (
297-
self.change_y < 0
298-
and self.change_x == 0
299-
and self.state != FACE_DOWN
300-
and len(self.walk_down_textures) > 0
301-
):
302-
self.state = FACE_DOWN
303-
change_direction = True
304-
elif (
305-
self.change_y > 0
306-
and self.change_x == 0
307-
and self.state != FACE_UP
308-
and len(self.walk_up_textures) > 0
309-
):
310-
self.state = FACE_UP
311-
change_direction = True
312-
313-
if self.change_x == 0 and self.change_y == 0:
314-
if self.state == FACE_LEFT:
315-
self.texture = self.stand_left_textures[0]
316-
elif self.state == FACE_RIGHT:
317-
self.texture = self.stand_right_textures[0]
318-
elif self.state == FACE_UP:
319-
self.texture = self.walk_up_textures[0]
320-
elif self.state == FACE_DOWN:
321-
self.texture = self.walk_down_textures[0]
322-
323-
elif change_direction or distance >= self.texture_change_distance:
324-
self.last_texture_change_center_x = self.center_x
325-
self.last_texture_change_center_y = self.center_y
326-
327-
if self.state == FACE_LEFT:
328-
texture_list = self.walk_left_textures
329-
if texture_list is None or len(texture_list) == 0:
330-
raise RuntimeError(
331-
"update_animation was called on a sprite that doesn't have a "
332-
"list of walk left textures."
333-
)
334-
elif self.state == FACE_RIGHT:
335-
texture_list = self.walk_right_textures
336-
if texture_list is None or len(texture_list) == 0:
337-
raise RuntimeError(
338-
"update_animation was called on a sprite that doesn't have a list of "
339-
"walk right textures."
340-
)
341-
elif self.state == FACE_UP:
342-
texture_list = self.walk_up_textures
343-
if texture_list is None or len(texture_list) == 0:
344-
raise RuntimeError(
345-
"update_animation was called on a sprite that doesn't have a list of "
346-
"walk up textures."
347-
)
348-
elif self.state == FACE_DOWN:
349-
texture_list = self.walk_down_textures
350-
if texture_list is None or len(texture_list) == 0:
351-
raise RuntimeError(
352-
"update_animation was called on a sprite that doesn't "
353-
"have a list of walk down textures."
354-
)
355-
356-
self.cur_texture_index += 1
357-
if self.cur_texture_index >= len(texture_list):
358-
self.cur_texture_index = 0
359-
360-
self.texture = texture_list[self.cur_texture_index]
361-
362-
if self._texture is None:
363-
logger.warning("Error, no texture set")
364-
else:
365-
self.width = self._texture.width * self.scale_x
366-
self.height = self._texture.height * self.scale_y

‎arcade/sprite/enums.py‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)