scale To Pixels

Scale a sprite to a number of pixels in a direction from an anchor point.

mySprite32truesetscale topixelshorizontallyanchormiddle
JavaScript
function scaling.scaleToPixels(sprite: Sprite, value: number, direction: ScaleDirection, anchor: ScaleAnchor, proportional: boolean): void;
Python
def scaling.scale_to_pixels(sprite: Sprite, value: number, direction: ScaleDirection, anchor: ScaleAnchor, proportional: bool): None

A sprite can scale to a number of pixels in a direction from an anchor point. The scaling can be in just in the direction chosen, or the sprite can scale proportionally in the other direction too.

Proportional scaling

If the scale direction is vertically or horizontally but proportional is set to false, the sprite will scale to the number of pixels given in value only in the chosen direction. The sprite will expand in height but the width will stay the same or the sprite will expand in width but the height will stat the same.

If the scaling direction is vertically and the proportional parameter is true, the width will also expand by the same ratio of change as the height. With this setting, expanding a 32 x 16 sprite in the vertical direction to 32 pixels will also expand the width to 64. The same ratio scaling will happen for the height if the direction is horizontally.

Uniform scaling

When the scaling direction is set to uniformly, the sprite is scaled so that te new size will have both the width and height the same. If a sprite’s current size is 64 x 16 and it’s uniformly scaled to 128, the new width and height will both be 128.

Parameters

  • sprite: the sprite to scale to a pixel amount.
  • value: the number of pixels to scale the sprite to.
  • direction: the direction to scale in:
    • horizontally
    • vertically
    • uniformly
  • anchor: an anchor point to scale the sprite from:
    • middle
    • top
    • left
    • right
    • bottom
    • top left
    • top right
    • bottom right
    • bottom left
  • proportional: a boolean value that when true will scale the sprite proportionally. If false, the sprite will only scale by direction. This parameter has no effect when direction is set to uniformly.

Example

Scaling tester

Make a program to test sprite scaling in both directions for expanding and shrinking. Use the controller buttons to increase and decrease the scale. Use buttons to turn proportional to true or false.

false"Proportional = FALSE"show long textbottomsetproportiontoonBbuttonpressedtrue"Proportional = TRUE"show long textbottomsetproportiontoonAbuttonpressedmySpritepixelMinproportionsetscale topixelshorizontallyanchormiddleproportionalonleftbuttonpressedmySpritepixelMaxproportionsetscale topixelshorizontallyanchormiddleproportionalonrightbuttonpressedmySpritepixelMaxproportionsetscale topixelsverticallyanchormiddleproportionalonupbuttonpressedmySpritepixelMinproportionsetscale topixelsverticallyanchormiddleproportionalondownbuttonpressedPlayerspriteof kindmySpritewidthpixelMin5×"Proportional = FALSE"show long textbottomsetpixelMaxtosetpixelMintosetmySpritetoon start

Uniformity tester

Test uniformly scaling a nonsquare sprite. Use the up and down controller buttons to increase and decrease the scale.

mySpritepixelMaxmySpritewidthset score tosetscale topixelsuniformlyanchormiddleonupbuttonpressedmySpritepixelMinmySpritewidthset score tosetscale topixelsuniformlyanchormiddleondownbuttonpressedPlayerspriteof kindmySpriteheightpixelMin5×mySpritewidthset score tosetpixelMaxtosetpixelMintosetmySpritetoon start

See also

scale by pixels