Hello Reaching out for some help,
What I am trying to do is when I press mouse button a different part of an array is show and placed on the screen, what is happening is that even though the selected array index is the one being shown once I change the array pressing βcβ all of the objects placed already on the canvas change.
My final goal is to have a letter, click to place it down, change the letter, place it somewhere else, etc.
let tx = ["A", "B", "C", "D", "E", "8", "9", "1"];
class Bubbles {
constructor(x, y) {
this.x = x;
this.y = y;
}
preview() {
push();
translate(mouseX, mouseY);
text(tx[z], 0, 0);
pop();
}
show() {
textSize(100);
textAlign(CENTER, CENTER);
text(tx[placed], this.x, this.y);
}
}
let bubble = [];
let z = 0;
let placed = 0;
let targetX;
let targetY;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(255);
for (let i = 0; i < bubble.length; i++) {
bubble[i].preview();
bubble[i].show();
}
}
function mouseClicked() {
let b = new Bubbles(mouseX,mouseY);
bubble.push(b);
targetX = mouseX;
targetY = mouseY;
placed = z;
}
function keyPressed() {
if (key == "c") {
z++;
if (z == tx.length) {
z = 0;
}
}
}
Thank you in advance, if there is anything else I can provide to explain please let me know.
Thank you.