Skip to content

Commit be48ee9

Browse files
authored
Replace negative scale in background_parallax.py (#2440)
* Remove use of negative scale in background_parallax.py * Use simpler code based on 3.0's texture flip methods during loading / initialization * Remove comments and docstrings advising not to use now-deleted negative scale
1 parent fa960c1 commit be48ee9

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

arcade/examples/background_parallax.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,17 @@ def __init__(self):
7979
scale=PIXEL_SCALE
8080
)
8181

82+
# Load the car texture and create a flipped version
83+
self.car_texture_right = arcade.texture.load_texture(
84+
":resources:/images/miami_synth_parallax/car/car-idle.png")
85+
self.car_texture_left = self.car_texture_right.flip_left_right()
86+
8287
# Create & position the player sprite in the center of the camera's view
8388
self.player_sprite = arcade.Sprite(
84-
":resources:/images/miami_synth_parallax/car/car-idle.png",
89+
self.car_texture_right,
8590
center_x=self.camera.viewport_width // 2, center_y=-200.0, scale=PIXEL_SCALE
8691
)
92+
8793
self.player_sprite.bottom = 0
8894

8995
# Track the player's x velocity
@@ -123,17 +129,10 @@ def on_draw(self):
123129
arcade.draw_sprite(self.player_sprite, pixelated=True)
124130

125131
def update_car_direction(self):
126-
"""
127-
Don't use the trick below in a real game!
128-
129-
It will cause problems! Instead, use different textures, either
130-
from different files or by using Texture.flop_left_to_right().
131-
"""
132132
if self.x_velocity < 0:
133-
self.player_sprite.scale_xy = (-PIXEL_SCALE, PIXEL_SCALE)
134-
print(self.player_sprite.width)
133+
self.player_sprite.texture = self.car_texture_left
135134
elif self.x_velocity > 0:
136-
self.player_sprite.scale_xy = (PIXEL_SCALE, PIXEL_SCALE)
135+
self.player_sprite.texture = self.car_texture_right
137136

138137
def on_key_press(self, symbol: int, modifiers: int):
139138
if symbol == arcade.key.LEFT:

0 commit comments

Comments
 (0)