xxxxxxxxxx
36
let spritesheet;
let sprites = [];
let direction = 1; // 0 up
let step = 0;
let x;
let y;
let speed = 5;
function preload() {
spritesheet = loadImage("runningcat.png");
}
function setup() {
createCanvas(600, 600);
let w = spritesheet.width / 2;
let h = spritesheet.height / 4;
for (let y = 0; y < 4; y++) {
// create another emoty array for that row
sprites[y] = [];
// there are 12 images in a row, iterate through them
for (let x = 0; x < 2; x++) {
// get the image subsection there and then store in the array
sprites[y][x] = spritesheet.get(x * w, y * h, w, h);
}
}
x = width / 2;
y = height / 2;
}
function draw() {
background(220);
}