xxxxxxxxxx
43
let catAni, catIdle;
let cat;
function preload() {
catAni = loadAni(
"cat/cat_01.png",
"cat/cat_02.png",
"cat/cat_03.png",
"cat/cat_04.png",
"cat/cat_05.png",
"cat/cat_06.png"
);
catIdle = loadAni('cat/cat_03.png');
}
function setup() {
createCanvas(400, 400);
cat = new Sprite(width / 2, height - 100);
cat.addAnimation("running", catAni);
cat.addAnimation("idle", catIdle);
}
function draw() {
background(220);
if (kb.pressing("left")) {
cat.changeAni("running");
cat.vel.x = -2;
cat.mirror.x = true;
} else if (kb.pressing("right")) {
cat.changeAni("running");
cat.vel.x = 2;
cat.mirror.x = false;
} else {
cat.changeAni("idle");
cat.vel.x = 0;
}
cat.ani.play();
}