Skip to content

[Question] Set sprite width/height #1

@flashultra

Description

@flashultra

I'm wondering why you don't allow to set width and height of the Sprite ?
I am currently simulating such properties in OpenFL with the following code:

class AbstractSprite extends openfl.display.Sprite{
    
    public var dirty : Bool;
    public var allowScale:Bool = false;

    public function new() {
        super();
        this.graphics.beginFill(0xe3d523a6, 1);
		this.graphics.drawRect(0, 0, 1, 1);
		this.graphics.endFill();
        dirty = true;
    }

    @:keep @:noCompletion override private function set_scaleX(value:Float):Float
    {
        return allowScale?super.set_scaleX(value):super.set_scaleX(1);
    }
    
	@:keep @:noCompletion override private function set_scaleY(value:Float):Float {
		return allowScale?super.set_scaleY(value):super.set_scaleY(1);
	}
}	

class Sprite extends AbstractSprite {
  private override function set_width(value:Float):Float {
   if ( dirty ) {
     this.graphics.drawRect(0, 0, value, this.height);
   } else {
    super.set_width(value);
  }
  private override function set_height(value:Float):Float {
   .....
  }
 }

Changing width and height will change the scaleX/scaleY, so I set it to 1 (in the code above)
I also implement some scalling options that allow scaling of each element on the scene (and x/y coordinates ), which is important for mobile devices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions