Skip to content

Size.setSizeToFrame should mention default behaviour w/o frame; make parameter type optional #7325

Description

@Bertie690

Version

  • Phaser Version: 4.2.1
  • Operating system: N/A
  • Browser: N/A

Description

The setSizeToFrame method from the Size mixin claims to accept a boolean for the frame parameter, while leaving no mention as to what passing a boolean would even do.

Moreover, attempting to pass true (a valid boolean) to the function will set the object's width/height to undefined and likely cause a crash the next time said fields are used.

To fix this, I propose 2 solutions (all of which can likely be done in tandem):

  1. The function should document the fact that it defaults to the current frame if the frame parameter is omitted.
  2. The function's typing should be altered to change boolean to undefined and/or make the parameter entirely optional.

Example Test Code

sprite.setSizeToFrame(false); // non obvious, uses current frame
sprite.setSizeToFrame(true); // non obvious and crashes next time sprite is used
sprite.setSizeToFrame(); // would be most ergonomic and works at runtime, but gives type errors

Additional Information

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions