Skip to content
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

Replace warned-against use of negative scale with a cleaner flipped texture #2440

Merged
Merged
Changes from all commits
Commits
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
19 changes: 9 additions & 10 deletions arcade/examples/background_parallax.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,17 @@ def __init__(self):
scale=PIXEL_SCALE
)

# Load the car texture and create a flipped version
self.car_texture_right = arcade.texture.load_texture(
":resources:/images/miami_synth_parallax/car/car-idle.png")
self.car_texture_left = self.car_texture_right.flip_left_right()

# Create & position the player sprite in the center of the camera's view
self.player_sprite = arcade.Sprite(
":resources:/images/miami_synth_parallax/car/car-idle.png",
self.car_texture_right,
center_x=self.camera.viewport_width // 2, center_y=-200.0, scale=PIXEL_SCALE
)

self.player_sprite.bottom = 0

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

def update_car_direction(self):
"""
Don't use the trick below in a real game!

It will cause problems! Instead, use different textures, either
from different files or by using Texture.flop_left_to_right().
"""
if self.x_velocity < 0:
self.player_sprite.scale_xy = (-PIXEL_SCALE, PIXEL_SCALE)
print(self.player_sprite.width)
self.player_sprite.texture = self.car_texture_left
elif self.x_velocity > 0:
self.player_sprite.scale_xy = (PIXEL_SCALE, PIXEL_SCALE)
self.player_sprite.texture = self.car_texture_right

def on_key_press(self, symbol: int, modifiers: int):
if symbol == arcade.key.LEFT:
Expand Down
Loading