HELP

1. Use the ASSETS buttons at the top to go to add pictures and sounds.

2. The names of the picked assets will be listed in the code comments.

3. Use the assets with new Pic("name") or new Aud("name"). SEE VIDEO

4. Scroll down and press the wands below to see helpful examples!

1. ADDING A BACKGROUND COLOR

SHOW ▼︎

To change the background color you can use the color property of the frame (F)

background colors and gradients for example of what we can make with SLATE and assets in ZIM!

01
// use the color property of the frame for the stage color
F.color = yellow; // F is the frame!

// use the outerColor property for the color outside the stage
F.outerColor = blue;

// use a Page to make a gradient 
new Page(W, H, green, pink).addTo();

2. ADDING A BACKGROUND PICTURE

SHOW ▼︎

We will add a picture of a BEACH for a background picture.

picture of a beach for example of what we can make with SLATE and assets in ZIM!

steps to add picture

  1. Press the Backings button at the top of the page
  2. Select and save the "beach01" picture
  3. You should see "Backings: beach01" in the comments
  4. Use the code below to put the asset on the stage

02
// ** DO THE STEPS ABOVE FIRST **
// A background picture can be scaled to the stage
// then center() and mov(x, y) or loc(x, y) can be used
new Pic("beach01")
   .scaleTo()
   .center();

3. ADDING PICTURES

SHOW ▼︎

Let's add a picture of a BUTTERFLY and make it draggable!

picture of a butterfly on a beach for example of what we can make with SLATE and assets in ZIM!

steps to add picture

  1. Press the Nature button at the top of the page
  2. Select and save the "bug01" picture
  3. You should see "Nature: bug01" in the comments
  4. Use the code below to put the asset on the stage

03
// pictures can be scaled with sca() if you want
// sca(.5) is half as big, sca(2) is twice as big
// You can use center() and mov(x, y) or
// loc(x, y) or pos(x, y, RIGHT, BOTTOM), etc. 
// Store the bug in a variable to use later with sounds
const bug = new Pic("bug01")
   .sca(.5)
   .center()
   .drag(); 

4. USING CONTAINERS

SHOW ▼︎

Sometimes we want to group our objects so they move together.
Let's put "gem01" and "cartoon02" in a Container and drag them.

gem with face in container for example of what we can make with SLATE and assets in ZIM!

steps to add pictures

  1. Select and save the "gem01" picture from Nature assets
  2. Select and save the "cartoon02" picture from People assets
  3. You should see the pictures listed in the comments
  4. Use the code below to put the pictures in a Container

04
// make a Container (an invisible holder)
const holder = new Container();

// add the gem 
new Pic("gem01").addTo(holder);

// scale the cartoon face to FIT in 60% the holder width 
// and center it in the container 
new Pic("cartoon02")
   .scaleTo(holder, 60) // 60% the size
   .center(holder);

// position the container and drag all of it together 
holder
   .pos(100,50,RIGHT,BOTTOM)
   .drag({all:true});

5. ADDING SOUNDS

SHOW ▼︎

Here we play a POWERUP sound when we press the butterfly!

steps to add sound

  1. Press the Sounds button at the top of the page
  2. Select and save the "powerup" sound
  3. You should see "Sounds: powerup" in the comments
  4. Use the code below play the sound when pressing the butterfly

05
// To play a sound when pressing the bug (from above)
// use an event and play the sound in the event function
// Aud is short form for Audio - another way to say sound!
const sound = new Aud("powerup"); // make the sound once
bug.on("mousedown", ()=>{
   sound.play(); // play the sound every time we press the bug
}); 

6. ADDING A BACKGROUND SOUND

SHOW ▼︎

Let's play some BACKING music. We show four ways to play a background sound because sounds can only be played after the first mousedown.

steps to add sound

  1. Press the Sounds button at the top of the page
  2. Select and save the "backing" sound
  3. From wand 5 you may already have a powerup sound
  4. So you should see "Sounds: backing, powerup" in the comments
  5. Use ONE of the examples below to play the background sound

06
// ** OPTION ONE - BASIC **
// This code works when we TEST to play a backing sound
// but will not work when we use FULL and SAVE - boo!
// Here we lower the volume and loop the backing sound.  
new Aud("backing").play(.1, true);

07
// ** OPTION TWO - PANE **
// This code works in TEST, FULL and SAVE. Yay!
// Here we play the backing sound once a Pane() is closed.
new Pane("START", yellow).show(()=>{
   new Aud("backing").play(.1, true);
});

A start Pane so sound plays when in FULL or SAVE modes


08
// ** OPTION THREE - TOGGLE **
// This code lets people turn on and off the sound.
// Do not worry if this is complicated looking 
// it will just help you pause or play the sound.
let backingSound;
const toggle = new Toggle({
   label:"music",
   startToggled:false
})
   .sca(.7)
   .pos(40,40,LEFT,BOTTOM)
   .change(()=>{
      if (!backingSound) {
         backingSound = new Aud("backing").play(.1, true);
      }
      backingSound.paused = !toggle.toggled;
   }); 
    
a pause button for sound that will work everywhere


09
// ** OPTION FOUR - BUTTON **
// This code uses a Button to toggle sound.
// We use pizzazz to make sound icons 
// or you could use label:"play" and toggle:"mute"
// We use the tap() method which is like on("click", function).
let backingSound;
const button = new Button({
   width:60,
   height:60,
   corner:0,
   backgroundColor:purple,
   rollBackgroundColor:pink,
   icon:makeIcon("sound", white),
   toggleIcon:makeIcon("mute", white)
}).pos(50,50,LEFT,BOTTOM).tap(()=>{
   if (!backingSound) {
      backingSound = new Aud("backing").play(.1, true);
   }
   backingSound.paused = !button.toggled;
});
    
a toggle button for sound that will work everywhere


7. ADDING SPRITES

SHOW ▼︎

Sprites are animated pictures! They will say SPRITE beneath the asset picture and how many COLS and ROWS make the animation. Here is a Video about Sprites
Picture of SpriteSheet with columns across the top and rows down the side

steps to add a sprite

  1. Press the NATURE button at the top of the page
  2. Select and save the "monkey" picture
  3. You should see "Nature: monkey" in the comments
  4. Use the code below to animate the sprite

10
// The Sprite is made from a SpriteSheet.
// A SpriteSheet has columns and rows.
// The columns and rows are beneath the menu picture.
// We must run() the sprite as well 
// which is like animate() but for Sprites.
// The longer the time the slower the animation.
new Sprite("monkey", 4, 4)
   .center()
   .run({time:1, loop:true});


8. ADDING ASSETS FROM INTERNET

SHOW ▼︎

Pictures, Sounds and Sprites can be loaded from the Internet. There may be permission issues so talk to your leader.

11
// Here we load from the ZIM assets folder.
// See assets:  https://zimjs.org/assets/ 

PATH = "https://zimjs.org/assets/"; // tell ZIM where the assets are

new Pic("nature03.jpg")
   .scaleTo()
   .center();
const start = new Aud("start.mp3");
const bike = new Pic("transport03.png")
   .reg(CENTER,BOTTOM)
   .pos(0,100,CENTER,BOTTOM)
   .tap(()=>{
      start.play();
      bike.animate({x:-200}, 3, "backIn");
});


12
// For a Sprite, we have to preload the asset
// We normally load assets in the ZIM Frame()
// but the Frame is already made in Slate
// so instead, we can use loadAssets()

// this sprite is packed so needs json data
F.loadAssets(["spaceguy.png", "spaceguy.json"], "https://zimjs.org/assets/");
F.on("complete", ()=>{
   new Sprite({json:"spaceguy.json"})
      .sca(2)
      .center()
      .run({loop:true});
});

// See sidescroller examples with mouse:
//  Sidescroller with Mouse 
// with keyboard and shooting:
//  Sidescroller with Keys