xxxxxxxxxx
56
let spritesheet1;
let spritesheet2;
let walk = [];
let jump=[];
let ponyJump;
let ponyWalk;
function preload() {
spritesheet1 = loadImage('pinkiePieWalk.png');
spritesheet2 = loadImage('pinkiePieJump.png');
}
function setup() {
createCanvas(400, 400);
//background(220);
let w1 = int(spritesheet1.width / 6);
let h1=int(spritesheet1.height);
let w2 = int(spritesheet2.width / 6);
let h2=int(spritesheet2.height);
for (let x = 0; x < 6; x++) {
walk[x] = spritesheet1.get(x * w1, 0, w1, h1);
}
for (let x = 0; x < 6; x++) {
jump[x] = spritesheet2.get(x * w2, 0, w2, h2);
}
ponyJump= new Sprite(jump,0,200, 0.1);
ponyWalk= new Sprite(walk,0,200, 0.1);
}
function keyPressed(){
if (key ==" ") {
ponyJump.show();
ponyJump.animate();
}
}
function draw() {
background(220);
ponyWalk.show();
ponyWalk.animate();
if(key ==" ") {
ponyJump.show();
ponyJump.jump();
}
}