@@ -482,10 +482,6 @@ def set_frame(self, frame=None, rotation=None):
482
482
def update (self ):
483
483
pass
484
484
485
- def _updated (self ):
486
- self .px = int (self .x )
487
- self .py = int (self .y )
488
-
489
485
490
486
class Text :
491
487
"""Text layer. For displaying text."""
@@ -584,6 +580,8 @@ def __init__(self, display, fps=6, scale=None):
584
580
self .height = display .height // self .scale
585
581
self .last_tick = time .monotonic ()
586
582
self .tick_delay = 1 / fps
583
+ self .vx = 0
584
+ self .vy = 0
587
585
588
586
def tick (self ):
589
587
"""Wait for the start of the next frame."""
@@ -594,32 +592,39 @@ def tick(self):
594
592
else :
595
593
self .last_tick = time .monotonic ()
596
594
597
- def render_block (self , x0 = 0 , y0 = 0 , x1 = None , y1 = None ):
595
+ def render_block (self , x0 = None , y0 = None , x1 = None , y1 = None ):
598
596
"""Update a rectangle of the screen."""
597
+ if x0 is None :
598
+ x0 = self .vx
599
+ if y0 is None :
600
+ y0 = self .vy
599
601
if x1 is None :
600
- x1 = self .width
601
- else :
602
- x1 = min (max (1 , x1 ), self .width )
602
+ x1 = self .width + self .vx
603
603
if y1 is None :
604
- y1 = self .height
605
- else :
606
- y1 = min (max (1 , y1 ), self .height )
604
+ y1 = self .height + self .vy
605
+ x0 = min (max (0 , x0 - self .vx ), self .width - 1 )
606
+ y0 = min (max (0 , y0 - self .vy ), self .height - 1 )
607
+ x1 = min (max (1 , x1 - self .vx ), self .width )
608
+ y1 = min (max (1 , y1 - self .vy ), self .height )
607
609
if x0 >= x1 or y0 >= y1 :
608
610
return
609
611
layers = [l .layer for l in self .layers ]
610
612
_stage .render (x0 , y0 , x1 , y1 , layers , self .buffer ,
611
- self .display , self .scale )
613
+ self .display , self .scale , self . vx , self . vy )
612
614
613
615
def render_sprites (self , sprites ):
614
616
"""Update the spots taken by all the sprites in the list."""
615
617
layers = [l .layer for l in self .layers ]
616
618
for sprite in sprites :
617
- x0 = max (0 , min (self .width - 1 , min (sprite .px , int (sprite .x ))))
618
- y0 = max (0 , min (self .height - 1 , min (sprite .py , int (sprite .y ))))
619
- x1 = max (1 , min (self .width , max (sprite .px , int (sprite .x )) + 16 ))
620
- y1 = max (1 , min (self .height , max (sprite .py , int (sprite .y )) + 16 ))
619
+ x = int (sprite .x ) - self .vx
620
+ y = int (sprite .y ) - self .vy
621
+ x0 = max (0 , min (self .width - 1 , min (sprite .px , x )))
622
+ y0 = max (0 , min (self .height - 1 , min (sprite .py , y )))
623
+ x1 = max (1 , min (self .width , max (sprite .px , x ) + 16 ))
624
+ y1 = max (1 , min (self .height , max (sprite .py , y ) + 16 ))
625
+ sprite .px = x
626
+ sprite .py = y
621
627
if x0 >= x1 or y0 >= y1 :
622
628
continue
623
629
_stage .render (x0 , y0 , x1 , y1 , layers , self .buffer ,
624
- self .display , self .scale )
625
- sprite ._updated ()
630
+ self .display , self .scale , self .vx , self .vy )
0 commit comments