xxxxxxxxxx
26
// Welcome to p5.play Version 3!
// https://p5play.org/learn/sprite.html
function setup() {
new Canvas(800, 400);
}
function draw() {
background(255);
fill(0);
textSize(24);
textAlign(CENTER);
text('Click to create a new sprite', width/2, height/2);
if (mouse.presses()) {
let sprite = new Sprite(mouse.x, mouse.y, 30, 30);
// sprites have many properties you can edit
// here the x and y velocities of the sprite are edited
sprite.vel.x = random(-5, 5);
sprite.vel.y = random(-5, 5);
// try editing the sprite's speed!
}
}