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

[Question] Set sprite width/height #1

Open
flashultra opened this issue Sep 12, 2024 · 0 comments
Open

[Question] Set sprite width/height #1

flashultra opened this issue Sep 12, 2024 · 0 comments

Comments

@flashultra
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant