ppb / pursuedpybear

A python game engine.
https://ppb.dev/
Artistic License 2.0
258 stars 98 forks source link

set dimensions for missing image #700

Closed davidism closed 7 months ago

davidism commented 7 months ago

When a RectangleSprite falls back to rendering a default shape instead of an image, use its dimensions rather than a default square.

This adds a private _file_missing_dimensions tuple to Image, which defaults to (1, 1). RectangleSprite.__image__ sets this to its dimensions so that the default shape is a rectangle instead of a square.

fixes #691

import ppb

class Platform(ppb.RectangleSprite):
    pass

class Player(ppb.Sprite):
    pass

def setup(scene):
    platform = Platform(width=3, height=1, position=ppb.Vector(0, -5))
    scene.add(platform)
    player = Player()
    scene.add(player)

ppb.run(setup)
Screenshot 2024-04-08 at 09 57 41