On this page:
run
land%
new
watch
sprite%
new
forward
move-x
move-y
set-x
set-y
get-x
get-y
turn
turn-to
change-size
show
hide
set-image
say
hush
tell
broadcast
get-land
set-land

2 Runtime Functions and Classes

 (require scratchy/runtime) package: scratchy

procedure

(run land)  void?

  land : land%
Runs a Scratchy program given a starting land. The sprites in the land are drawn last to first in the order of addition to the land (so the last added sprite is drawn under all others, for example).

class

land% : class?

  superclass: object%

A land that holds sprites and connections to other lands. One land is displayed at a time, and the displayed land can be changed with the watch method.

constructor

(new land% [get-lands get-lands])  (is-a?/c land%)

  get-lands : (-> (listof (is-a?/c land%)))
Creates a land, given a procedure that gets connected lands when the Scratchy program starts. The get-lands callbacks for different lands can include each land in the other’s lists. The lands available in the Scratchy world include the all of the lands reachable from the one given to run.

method

(send a-land watch)  void?

Switches the Scratchy world view to this land.

class

sprite% : class?

  superclass: object%

A sprite implemented by the sprite% class is a character in the Scratchy world. Each sprite has an image, a position on the screen (where the origin is in the center of the Scratchy world and positive Y-values correspond to north), a scale, an orientation (in degrees), and an optional cartoon bubble.
The sprite’s public methods are all thread safe, and they work by synchronizing with the eventspace in which Scratchy is run.

constructor

(new sprite% 
    [land land] 
    [image image] 
    [[x x] 
    [y y] 
    [key-callback key-callback] 
    [mouse-callback mouse-callback] 
    [message-callback message-callback]]) 
  (is-a?/c sprite%)
  land : (is-a?/c land%)
  image : convertible?
  x : real? = 0
  y : real? = 0
  key-callback : (boolean? (or/c symbol? char?) . -> . any)
   = void
  mouse-callback : (boolean? real? real? . -> . any) = void
  message-callback : (any/c . -> . any) = void
Creates a sprite that is initially in land.

The key-callback function is called in a fresh thread for any key press or release in the Scratchy world, where the initial boolean argument is #t for a key press and #f for a key release.

The mouse-callback function is called in a fresh thread for a mouse click on the sprite.

The message-callback function is called in a fresh thread for a tell or broadcast call.

method

(send a-sprite forward steps)  void?

  steps : real?
Moves the sprite in the direction of its current orientation.

method

(send a-sprite move-x steps)  void?

  steps : real?
Changes the sprite’s location in the X direction.

method

(send a-sprite move-y steps)  void?

  steps : real?
Changes the sprite’s location in the Y direction.

method

(send a-sprite set-x pos)  void?

  pos : real?
Sets the sprite’s location in the X direction.

method

(send a-sprite set-y pos)  void?

  pos : real?
Sets the sprite’s location in the Y direction.

method

(send a-sprite get-x)  real?

Gets the sprite’s location in the X direction.

method

(send a-sprite get-y)  real?

Gets the sprite’s location in the Y direction.

method

(send a-sprite turn degrees)  void?

  degrees : real?
Changes the sprite’s orientation by turning it counter-clockwise.

method

(send a-sprite turn-to degrees)  void?

  degrees : real?
Sets the sprite’s orientation.

method

(send a-sprite change-size amount)  void?

  amount : real?
Changes the sprite’s size as a factor of its original size by adding amount to the current factor.

method

(send a-sprite show)  void?

Makes the sprite visible.

method

(send a-sprite hide)  void?

Makes the sprite invisible.

method

(send a-sprite set-image image)  void?

  image : convertible?
Sets the sprite’s image.

method

(send a-sprite say v)  void?

  v : any/c
Sets the sprite’s speech balloon to show v.

method

(send a-sprite hush)  void?

Removes the sprite’s speech balloon, if any.

method

(send a-sprite tell s v)  void?

  s : (is-a?/c other-sprite)
  v : any/c
Calls other-sprite’s message callback with v in a new thread.

method

(send a-sprite broadcast v)  void?

  v : any/c
For every sprite in the same land, calls the sprite’s message callback with v in a new thread.

method

(send a-sprite get-land)  (is-a?/c land%)

Returns the sprite’s land.

method

(send a-sprite set-land land)  void?

  land : (is-a?/c land%)
Returns the sprite’s land to land, removing the sprite from its current land.