Scratch for Java

Sprite::setSize()

Sets the sprite's size to the percentage.

You this methode wisely, since it is slow. If you want to resize a sprite just once, consider reducing the size of the original image.

Examples

import org.openpatch.scratch.Sprite;
import org.openpatch.scratch.Stage;
 
public class SpriteSetSize {
  public SpriteSetSize() {
    Stage myStage = new Stage(600, 240);
    Sprite mySprite = new Sprite("zeta", "assets/zeta_green_badge.png");
    myStage.add(mySprite);
    mySprite.changeX(-80);
    mySprite.changeY(30);
    mySprite.say("Size: " + mySprite.getSize());
    myStage.wait(2000);
    mySprite.setSize(50);
    mySprite.say("Size: " + mySprite.getSize());
    myStage.wait(2000);
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new SpriteSetSize();
  }
}
 

View on GitHub

Syntax

Java

.setSize(percentage)

Scratch

set size to (50) %

Parameters

Name Data Type Description
percentage float A value in percent.

Return

void

setSize()