Skip to content

Name scale properties on Sprites to things that make sense #2021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c3b7537
incomplete scale fix
DigiDuncan Mar 13, 2024
1fd2830
fix a bunch of tests
DigiDuncan Mar 14, 2024
4a9081c
fix more tests
DigiDuncan Mar 14, 2024
57082ad
typo
DigiDuncan Mar 14, 2024
6ef286e
fix the one broken test and speed up .scale setter
DigiDuncan Mar 14, 2024
97ec420
fix docstrings
DigiDuncan Mar 14, 2024
d62528d
Fix examples
Cleptomania Mar 15, 2024
928e8fd
typing go brrr
DigiDuncan Apr 16, 2024
b22b8ad
Merge branch 'development' into scale_prop_name_fix
einarf Jun 30, 2024
0309c91
Remove overly strict Point annotation
pushfoo Jun 30, 2024
012fd1a
Fix misuse of Point annotation which should be Point2
pushfoo Jul 1, 2024
7f0b2a7
Fix set_size tests w/ notes on problems with == in pyglet==2.1dev2
pushfoo Jul 1, 2024
5a3f42f
Add temp fix for pyglet 2.1dev2
pushfoo Jul 1, 2024
41ca518
Remove Vec2 from test_set_size()
pushfoo Jul 1, 2024
43d2174
Update BasicSprite.scale and tests for it
pushfoo Jul 1, 2024
54678c6
Fix formatting to make CI happy
pushfoo Jul 1, 2024
fa542b2
Add optimized validation for BasicSprite.size + tests
pushfoo Jul 1, 2024
30e92e1
Optimize & clean up BasicSprite.scale_x setter
pushfoo Jul 1, 2024
06d9ed8
Optimize & clean up BasicSprite.scale_y setter
pushfoo Jul 1, 2024
ccd6321
Optimize and clean up scale setter
pushfoo Jul 1, 2024
de3d712
Revert use of assert in size.setter since digi was right
pushfoo Jul 1, 2024
b98d46a
Clean up rescale_relative_to_point's insides
pushfoo Jul 1, 2024
176b5b9
Update rescale_relative_to_point's docstring
pushfoo Jul 1, 2024
9254388
Unify rescale*_relative_to_point methods
pushfoo Jul 1, 2024
09b6b46
Apply auto-formatting
pushfoo Jul 1, 2024
bc88332
Fix typo
pushfoo Jul 1, 2024
db73158
Make Sphinx build
pushfoo Jul 1, 2024
a2e6cd4
Fix use of Point with Point2
pushfoo Jul 1, 2024
1f35b0d
Add detailed explanation of seemingly strange Vec2 usage
pushfoo Jul 1, 2024
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
11 changes: 11 additions & 0 deletions arcade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ def configure_logging(level: Optional[int] = None):
# noinspection PyPep8
import pyglet

# TODO: Remove ASAP after pyglet >= 2.1dev2 is out
if pyglet.version == "2.1.dev2":
# Temporary monkeypatch via deletion since dev2 still includes
# overly-specific __eq__ behavior. Later pyglet commits restore
# equality with same-valued tuples by deleting the __eq__ methods.
from pyglet import math as _pyglet_math

del _pyglet_math.Vec2.__eq__
del _pyglet_math.Vec3.__eq__
del _pyglet_math.Vec4.__eq__

# Env variable shortcut for headless mode
if os.environ.get("ARCADE_HEADLESS"):
pyglet.options["headless"] = True
Expand Down
2 changes: 1 addition & 1 deletion arcade/examples/particle_fireworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def firework_spark_mutator(particle: FadeParticle):


def rocket_smoke_mutator(particle: LifetimeParticle):
particle.scale = lerp(0.5, 3.0, particle.lifetime_elapsed / particle.lifetime_original)
particle.scale = lerp(0.5, 3.0, particle.lifetime_elapsed / particle.lifetime_original) # type: ignore


def main():
Expand Down
16 changes: 8 additions & 8 deletions arcade/examples/sprite_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, bar_list: arcade.SpriteList) -> None:
scale=SPRITE_SCALING_PLAYER,
)
self.indicator_bar: IndicatorBar = IndicatorBar(
self, bar_list, (self.center_x, self.center_y), scale=1.5,
self, bar_list, (self.center_x, self.center_y), scale=(1.5, 1.5),
)
self.health: int = PLAYER_HEALTH

Expand Down Expand Up @@ -98,7 +98,7 @@ def __init__(
width: int = 100,
height: int = 4,
border_size: int = 4,
scale: float = 1.0,
scale: Tuple[float, float] = (1.0, 1.0),
) -> None:
# Store the reference to the owner and the sprite list
self.owner: Player = owner
Expand All @@ -110,7 +110,7 @@ def __init__(
self._center_x: float = 0.0
self._center_y: float = 0.0
self._fullness: float = 0.0
self._scale: float = 1.0
self._scale: Tuple[float, float] = (1.0, 1.0)

# Create the boxes needed to represent the indicator bar
self._background_box: arcade.SpriteSolidColor = arcade.SpriteSolidColor(
Expand Down Expand Up @@ -206,8 +206,8 @@ def fullness(self, new_fullness: float) -> None:
else:
# Set the full_box to be visible incase it wasn't then update the bar
self.full_box.visible = True
self.full_box.width = self._bar_width * new_fullness * self.scale
self.full_box.left = self._center_x - (self._bar_width / 2) * self.scale
self.full_box.width = self._bar_width * new_fullness * self.scale[0]
self.full_box.left = self._center_x - (self._bar_width / 2) * self.scale[0]

@property
def position(self) -> Tuple[float, float]:
Expand All @@ -224,15 +224,15 @@ def position(self, new_position: Tuple[float, float]) -> None:
self.full_box.position = new_position

# Make sure full_box is to the left of the bar instead of the middle
self.full_box.left = self._center_x - (self._bar_width / 2) * self.scale
self.full_box.left = self._center_x - (self._bar_width / 2) * self.scale[0]

@property
def scale(self) -> float:
def scale(self) -> Tuple[float, float]:
"""Returns the scale of the bar."""
return self._scale

@scale.setter
def scale(self, value: float) -> None:
def scale(self, value: Tuple[float, float]) -> None:
"""Sets the new scale of the bar."""
# Check if the scale has changed. If so, change the bar's scale
if value != self.scale:
Expand Down
4 changes: 2 additions & 2 deletions arcade/hitbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(
self,
points: Point2List,
position: Point2 = (0.0, 0.0),
scale: tuple[float, float] = (1.0, 1.0),
scale: Point2 = (1.0, 1.0),
):
self._points = points
self._position = position
Expand Down Expand Up @@ -249,7 +249,7 @@ def __init__(
*,
position: tuple[float, float] = (0.0, 0.0),
angle: float = 0.0,
scale: tuple[float, float] = (1.0, 1.0),
scale: Point2 = (1.0, 1.0),
):
super().__init__(points, position=position, scale=scale)
self._angle: float = angle
Expand Down
2 changes: 1 addition & 1 deletion arcade/pymunk_physics_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def velocity_callback(

# Set the physics shape to the sprite's hitbox
poly = sprite.hit_box.points
scaled_poly = [[x * sprite.scale for x in z] for z in poly]
scaled_poly = [[x * sprite.scale_x for x in z] for z in poly]
shape = pymunk.Poly(body, scaled_poly, radius=radius) # type: ignore

# Set collision type, used in collision callbacks
Expand Down
4 changes: 2 additions & 2 deletions arcade/sprite/animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,5 @@ def update_animation(self, delta_time: float = 1 / 60) -> None:
if self._texture is None:
print("Error, no texture set")
else:
self.width = self._texture.width * self.scale
self.height = self._texture.height * self.scale
self.width = self._texture.width * self.scale_x
self.height = self._texture.height * self.scale_x
Loading
Loading