xxxxxxxxxx
41
// https://codeshack.io/images-sprite-sheet-generator/
//go to p5 library p5.play
let spritesheet;
let spritedata;
let animation = [];
let ninjas = [];
function preload() {
spritedata = loadJSON('ninja.json');
spritesheet = loadImage('spritesheet.png');
}
function setup() {
createCanvas(640, 480);
let frames = spritedata.frames;
for (let i = 0; i < frames.length; i++) {
let pos = frames[i].position;
let img = spritesheet.get(pos.x, pos.y, pos.w, pos.h);
animation.push(img);
}
ninja = new Sprite(animation, 100, 100, 1);
for (let i = 0; i < 5; i++) {
ninjas[i] = (animation, 0, i * 75, random(0.1, 0.4));
}
}
function draw() {
background(255);
for (let ninja of ninjas) {
ninja.show();
ninja.animate();
}
}
// https://thecodingtrain.com/CodingChallenges/111-animated-sprite.html