Hi
I’m new in P5 and need a help with “mouse dragged”
my code is:
let imgB;
let imgC;
let imgD;
let sz = 70
let y = 0;
let x = 0;
let y1 = 0;
let x1 = 0;
let y2 = 0;
let x2 = 0;
let startX = 0;
let startY = 0;
let startX1 = 0;
let startY1 = 0;
let startX2 = 0;
let startY2 = 0;
let speed = 3;
function preload() {
imgB = loadImage(‘Mircantha.Peq.Br.png’);
imgC = loadImage(‘Agrestis.Peq.Br.png’);
imgD = loadImage(‘R.Bl.Peq.Br.png’);
}
function setup() {
createCanvas(600, 600);
}
function draw() {
background(0);
//img Mirc.
image(imgB, x, y, sz, sz)
x = x + speed * 0.5;
y = y + speed * 0.3;
if (x > 600) {
x = -x;
}
if (y > 600) {
y = -y;
}
//img Agres.
image(imgC, x1, y1, sz, sz);
x1 = x1 + speed * 0.4;
y1 = y1 + speed * 0.1;
if (x1 > 600) {
x1 = -x1;
}
if (y1 > 600) {
y1 = -y1;
}
//img R.Bl
image(imgD, x2, y2, sz, sz);
x2 = x2 + speed * 0.3;
y2 = y2 + speed * 0.4;
if (x2 > 600) {
x2 = -1;
}
if (y2 > 600) {
y2 = -1;
}
function mousePressed() {
if (dist(x, y, mouseX, mouseY) < sz / 2) {
startX = mouseX;
startY = mouseY;
}
if (dist(x1, y1, mouseX, mouseY) < sz / 2) {
startX1 = mouseX;
startY1 = mouseY;
}
if (dist(x2, y2, mouseX, mouseY) < sz / 2) {
startX2 = mouseX;
startY2 = mouseY;
}
}
function mouseDragged() {
if (dist(x1, y1, mouseX, mouseY) < sz / 2) {
diff = startX - mouseX;
x = x - diff;
startX = mouseX;
diff1 = startY - mouseY;
y = y - diff;
startY = mouseY;
}
if (dist(x1, y1, mouseX, mouseY) < sz / 2) {
diff2 = startX1 - mouseX;
x1 = x1 - diff2;
startX1 = mouseX;
diff3 = startY1 - mouseY;
y1 = y1 - diff3;
startY1 = mouseY;
}
if (dist(x2, y2, mouseX, mouseY) < sz / 2) {
diff4 = startX2 - mouseX;
x2 = x2 - diff4;
startX2 = mouseX;
diff5 = startY2 - mouseY;
y2 = y2 - diff5;
startY2 = mouseY;
}
}
}
but…that is not working
There is some one that can help me??
Thaks