mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 13:08:09 +08:00 
			
		
		
		
	Adding a new method for sprite to render it scaled easily
This commit is contained in:
		@ -81,6 +81,18 @@ class Sprite {
 | 
				
			|||||||
    return new Position(src.width, src.height);
 | 
					    return new Position(src.width, src.height);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /// Renders this Sprite on the position [p], scaled by the [scale] factor provided.
 | 
				
			||||||
 | 
					  ///
 | 
				
			||||||
 | 
					  /// It renders with src size multiplied by [scale] in both directions.
 | 
				
			||||||
 | 
					  /// Anchor is on top left as default.
 | 
				
			||||||
 | 
					  /// If not loaded, does nothing.
 | 
				
			||||||
 | 
					  void renderScaled(Canvas canvas, Position p, [double scale = 1.0]) {
 | 
				
			||||||
 | 
					    if (!this.loaded()) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    renderPosition(canvas, p, size.times(scale));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void renderPosition(Canvas canvas, Position p, [Position size]) {
 | 
					  void renderPosition(Canvas canvas, Position p, [Position size]) {
 | 
				
			||||||
    if (!this.loaded()) {
 | 
					    if (!this.loaded()) {
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user