Scratch for Java

Sprite::setDirection()

Sets the direction of the sprite.

Examples

import org.openpatch.scratch.*;
 
public class SpriteSetDirection {
  public SpriteSetDirection() {
    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("Direction: " + mySprite.getDirection());
    myStage.wait(2000);
    mySprite.setDirection(45);
    mySprite.say("Direction: " + mySprite.getDirection());
    myStage.wait(2000);
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new SpriteSetDirection();
  }
}
 

View on GitHub

Syntax

Java

.setDirection(angle), .setDirection(vector)

Scratch

point in direction ()

Parameters

Name Data Type Description
angle float Direction angle. Initial direction is 0 and facing to the right.
vector Vector2 Vector for setting the direction

Return

void

setDirection()