pythonarcade / arcade

Easy to use Python library for creating 2D arcade games.
http://arcade.academy
Other
1.65k stars 312 forks source link

Broken examples (collection for 3.0) #2116

Open MiCurry opened 1 week ago

MiCurry commented 1 week ago

Some examples are broken due to the 3.0 camera updates. So far there are:

A few broken examples are listed in this comment. Others are listed in the comments below.

procedural_caves_bsp.py

Running python -m arcade.examples.procedural_caves_bsp the camera 'Jitters':

https://github.com/pythonarcade/arcade/assets/2590700/ed9a40db-a610-4155-9c8d-a8b1131f820c

procedural_caves_cellular.py

Running python -m arcade.examples.procedural_caves_cellular ends up in an attribute error:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/miles/programs/arcade/arcade/examples/procedural_caves_cellular.py", line 350, in <module>
    main()
  File "/Users/miles/programs/arcade/arcade/examples/procedural_caves_cellular.py", line 346, in main
    arcade.run()
  File "/Users/miles/programs/arcade/arcade/window_commands.py", line 146, in run
    pyglet.app.run(window._draw_rate)
  File "/usr/local/lib/python3.11/site-packages/pyglet/app/__init__.py", line 80, in run
    event_loop.run(interval)
  File "/usr/local/lib/python3.11/site-packages/pyglet/app/base.py", line 165, in run
    timeout = self.idle()
              ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyglet/app/base.py", line 226, in idle
    self.clock.call_scheduled_functions(dt)
  File "/usr/local/lib/python3.11/site-packages/pyglet/clock.py", line 217, in call_scheduled_functions
    item.func(now - item.last_ts, *item.args, **item.kwargs)
  File "/Users/miles/programs/arcade/arcade/application.py", line 386, in _dispatch_updates
    self.dispatch_event('on_update', delta_time)
  File "/usr/local/lib/python3.11/site-packages/pyglet/window/__init__.py", line 676, in dispatch_event
    super().dispatch_event(*args)
  File "/usr/local/lib/python3.11/site-packages/pyglet/event.py", line 380, in dispatch_event
    if handler(*args):
       ^^^^^^^^^^^^^^
  File "/Users/miles/programs/arcade/arcade/examples/procedural_caves_cellular.py", line 129, in on_update
    game_view.setup()
  File "/Users/miles/programs/arcade/arcade/examples/procedural_caves_cellular.py", line 209, in setup
    self.scroll_to_player(1.0)
  File "/Users/miles/programs/arcade/arcade/examples/procedural_caves_cellular.py", line 314, in scroll_to_player
    arcade.camera.controllers.simple_follow_2D(speed, position, self.camera_sprites.view_data)
    ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'arcade.camera' has no attribute 'controllers'
MiCurry commented 1 week ago

I haven't done much digging, but I believe the problematic code is in the scrolling section of on_update:

https://github.com/pythonarcade/arcade/blob/cf291ec55c103dd8d22e8efb1ca28d12baadee2f/arcade/examples/procedural_caves_bsp.py#L430-L457

When I removed that code, the jitters went away.

MiCurry commented 1 week ago

Slightly related the procedural_caves_cellular.py example also appears to be broken. I can create another issue for this if that would be better.

python -m arcade.examples.procedural_caves_cellular

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/miles/programs/arcade/arcade/examples/procedural_caves_cellular.py", line 350, in <module>
    main()
  File "/Users/miles/programs/arcade/arcade/examples/procedural_caves_cellular.py", line 346, in main
    arcade.run()
  File "/Users/miles/programs/arcade/arcade/window_commands.py", line 146, in run
    pyglet.app.run(window._draw_rate)
  File "/usr/local/lib/python3.11/site-packages/pyglet/app/__init__.py", line 80, in run
    event_loop.run(interval)
  File "/usr/local/lib/python3.11/site-packages/pyglet/app/base.py", line 165, in run
    timeout = self.idle()
              ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyglet/app/base.py", line 226, in idle
    self.clock.call_scheduled_functions(dt)
  File "/usr/local/lib/python3.11/site-packages/pyglet/clock.py", line 217, in call_scheduled_functions
    item.func(now - item.last_ts, *item.args, **item.kwargs)
  File "/Users/miles/programs/arcade/arcade/application.py", line 386, in _dispatch_updates
    self.dispatch_event('on_update', delta_time)
  File "/usr/local/lib/python3.11/site-packages/pyglet/window/__init__.py", line 676, in dispatch_event
    super().dispatch_event(*args)
  File "/usr/local/lib/python3.11/site-packages/pyglet/event.py", line 380, in dispatch_event
    if handler(*args):
       ^^^^^^^^^^^^^^
  File "/Users/miles/programs/arcade/arcade/examples/procedural_caves_cellular.py", line 129, in on_update
    game_view.setup()
  File "/Users/miles/programs/arcade/arcade/examples/procedural_caves_cellular.py", line 209, in setup
    self.scroll_to_player(1.0)
  File "/Users/miles/programs/arcade/arcade/examples/procedural_caves_cellular.py", line 314, in scroll_to_player
    arcade.camera.controllers.simple_follow_2D(speed, position, self.camera_sprites.view_data)
    ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'arcade.camera' has no attribute 'controllers'
einarf commented 1 week ago

Both are definitely related to changes applied when the new camera was added. These used to call arcade.set_viewport to do the scrolling but this function is now removed because the naming is highly misleading and camera can do this work much easier.

DragonMoffon commented 1 week ago

Yup, the example updates were not thorough enough. I will have to give them all another pass-over. Thank you for making the issue.

einarf commented 1 week ago

arcade\examples\full_screen_example.py

When swapping from fullscreen.

  File "arcade\camera\camera_2d.py", line 502, in projection
    self._projection_data.rect = value * _z
                                 ~~~~~~^~~~
TypeError: can't multiply sequence by non-int of type 'float'
einarf commented 1 week ago

arcade\examples\gl\custom_sprite.py

  File "arcade\examples\gl\custom_sprite.py", line 160, in on_mouse_drag
    self.cam.pos = self.cam.pos[0] - dx, self.cam.pos[1] - dy
                   ^^^^^^^^^^^^
einarf commented 3 days ago

arcade/examples/camera_platform.py is also broken

DragonMoffon commented 2 days ago

Another fix we (I) need to do in the examples is change them from saying cam to saying camera. Paul Craven mentioned it a while ago, and I forgot to write it down.

EDIT: this is now fixed in a coming PR

DragonMoffon commented 2 days ago

arcade/examples/easing_example_2.py

AttributeError: 'Player' object has no attribute 'face_point'
Exception ignored on calling ctypes callback function: <function Win32Window._get_window_proc.<locals>.f at 0x000001F91DE95800>
Traceback (most recent call last):
  File "C:\Users\Playtech\Desktop\Code\Python\ArcadeFork\arcade_dragon\.libs\Lib\site-packages\pyglet\window\win32\__init__.py", line 792, in f
    result = event_handler(msg, wParam, lParam)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Playtech\Desktop\Code\Python\ArcadeFork\arcade_dragon\.libs\Lib\site-packages\pyglet\window\win32\__init__.py", line 864, in _event_key
    self.dispatch_event(ev, symbol, modifiers)
  File "C:\Users\Playtech\Desktop\Code\Python\ArcadeFork\arcade_dragon\.libs\Lib\site-packages\pyglet\window\__init__.py", line 676, in dispatch_event
    super().dispatch_event(*args)
  File "C:\Users\Playtech\Desktop\Code\Python\ArcadeFork\arcade_dragon\.libs\Lib\site-packages\pyglet\event.py", line 392, in dispatch_event
    raise e
  File "C:\Users\Playtech\Desktop\Code\Python\ArcadeFork\arcade_dragon\.libs\Lib\site-packages\pyglet\event.py", line 387, in dispatch_event
    if getattr(self, event_type)(*args):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Playtech\Desktop\Code\Python\ArcadeFork\arcade_dragon\arcade\examples\easing_example_2.py", line 109, in on_key_press
    self.player_sprite.face_point(point)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Player' object has no attribute 'face_point'
DragonMoffon commented 2 days ago

Note on a few examples the resizing is a bit broken.

If they have a camera that isn't positioned every update (like a gui camera) add this line in the on_resize method

self.<camera in question>.position = self.center

or better completely remove the camera and just use the default camera i.e.

self.default_camera.use()

which is positioned and resized correctly at all times