0

I have been working on a new project "Maze", that's quite simple, but since I´m new to the program it´s a bit harder then i thought.

The problem is that i can´t place the background behind the image so that the object "circle" doesn´t duplicate itself all the time.

The other problem is that I want the mouseX and mouseY to start at (325, 75) and after that it changes position when i move the mouse.

The last thing I need help with is that when the circle/object hits the lines on the maze, it restarts at the position again.

let img;
let bacCol = "#ebf4ff";
let bg;
let xPos=325;
let yPos = 75;
let temp = 1;

function preload() {
  img = createImg("https://i.ibb.co/qWp4xJD/labyrint.png");
}

function setup() {
  createCanvas(700, 700);
  bg = loadImage("https://i.ibb.co/qWp4xJD/labyrint.png");
  img.hide();
}

function draw() {

  let col = {
    r: random(50, 255),
    g: random(50, 255),
    b: random(50, 255)
  }  

  image(img, 0,0,width,height);
  noStroke();
  fill(col.r, col.g, col.b);
  circle(xPos, yPos, 20);
  if(temp ===1){
    xPos = mouseX;
    yPos = mouseY;
  }


}

function keyPressed() {
  temp = 1;
}

Hopefully, i can get some help with this! Thanks in advance :)

  • One issue is that you are using `createImage(...)` in the preload function. This creates a `` tag in the html, not an image to be drawn to the canvas. Use `loadImage(...)` instead in the preload. Your `bg` variable is never used and you seemed to use it synonymously with the `img` variable. "The last thing I need help with is that when the circle/object hits the lines on the maze, it restarts at the position again." [JavaScript cannot move the mouse position.](https://stackoverflow.com/questions/4752501/move-the-mouse-pointer-to-a-specific-position) – Samathingamajig Oct 06 '20 at 04:16
  • Thank you @Samathingamajig! – Nicolai Amirzadeh Oct 20 '20 at 20:13

0 Answers0