You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Raise TypeError if Viewport is not a Rect and make Viewport (#2790)
* Make viewport a property/setter and raise TypeError if not a Rect
This commit makes viewport a property of Camera2D and adds a setter for it. In
the setter, and in __init__, we check that Viewport is a Rect and raise a
TypeError if it is not.
Without this check, an error will be raised after either calling
`Camera2D.equalise()` or in `Camera2D.use()`, which may confuse users as to why
the error is occurring.
Backtrace when calling `Camera2D.equalise()` with a non-rect viewport:
```
File "E:\Projects\SpaceGame\SpaceGame\gamemodes\basegame.py", line 128, in setup_two_player_cameras
player_one_camera.equalise()
File "E:\Programs\python-arcade\arcade\camera\camera_2d.py", line 336, in equalise
self._projection_data.rect = XYWH(x, y, self.viewport_width, self.viewport_height)
^^^^^^^^^^^^^^^^^^^
File "E:\Programs\python-arcade\arcade\camera\camera_2d.py", line 751, in viewport_width
return int(self._viewport.width)
```
Backtrace when calling `Camera2D.use()` with a non-rect viewport:
```
File "E:\Projects\SpaceGame\SpaceGame\gamemodes\pvp.py", line 139, in on_draw
self.cameras[player].use()
File "E:\Programs\python-arcade\arcade\camera\camera_2d.py", line 271, in use
self._window.ctx.viewport = self._viewport.lbwh_int
```
* Refactor viewport assignment and type check in camera_2d.py
---------
Co-authored-by: Maic Siemering <[email protected]>
0 commit comments