Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
I can't seem to be able to make a hittable image (tries to make image a function)

so I have been trying to make an aim trainer with javascript p5, but when I try to load in an image as an randomly shootable target it doesnt seem to let me click the image. I dont really understand why since I am new to coding. also the clicking on the normal ellipse doesnt work. but right now thats not what I am worrying about.

error: TypeError: img2 is not a function at draw (/script.js:82:5) at p5._main.default.redraw (https://cdn.jsdelivr.net/npm/p5@1.3.1/lib/p5.js:70718:27) at _draw (https://cdn.jsdelivr.net/npm/p5@1.3.1/lib/p5.js:63058:25)

let MENU = 0;
let img;
let img2; // -------------------------------------------
var life = 3;
var score = 0;
var shootFail = 0;
var x, y;
const radius = 20;
function preload() {
  img = loadImage('GAME_logo.png')
  img2 = loadImage('durtburd.png')// -----------------------------------
}
function setup() {
  createCanvas(800, 600);
    
}
  function mousePressed() {
  // Check if mouse is inside the circle
  var d = dist(mouseX, mouseY, x, y);
  if (d < radius) {
    newCircle();
    score++;
  }
     console.log("text", mousePressed)
}

function newCircle() {
  x = random(750);
  y = random(550);
}

setInterval(newCircle, 1000);
function draw() {
  cursor('test2.cur');
  background(225);
  // maakt start reflex knop
  fill('darkgray');
  rect(50, 50, 200, 75);
  // maakt instructions knop
  fill('darkgray');
  rect(50, 200, 200, 75);
  // maakt start tracking knop
  fill('darkgray');
  rect(50, 350, 200, 75);
  //maakt de teksten aan
  textSize(25);
  fill('white');
  text('START', 60, 90); //start text
  text('REFLEX', 60, 110); // reflex text
  textSize(24);
  text('INSTRUCTIONS', 60, 250); // instuctions text
  textSize(25);
  text('START', 60, 390); // start text
  text('TRACKING', 60, 410); // tracking text
  scale(0.9)
  image(img, 320, 50, 530, 520) // loads the logo

  if (MENU == 1) { // START GAME
    noStroke();
    background(35, 39, 42);
    fill('white');
    textSize(20);
    text('Press escape to return to MENU', 500, 30);
    textSize(60);
    fill('red');
    text('♥'.repeat(life), 400, 300);
    fill('white');
    textSize(30);
    text("Score: " + score, width/2, height/2 + 40);
    text("Misses: " + shootFail, width/2, height/2 + 65);
    //ellipse(x, y, radius*2, radius*2);
    image(img2,x, y); //dont know how to implement this------------------------------------
    if (keyIsDown(27)) {
      MENU = 0;
    }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!