Hi. I’m having a lot of problems with things not working the way they should, and things not working the way other people say they should. Can you please critique my code? I’m new to coding and just hacking things together. I think some of my code is redundant and poorly written (use of let vs var?/do i need to load the files twice?/are things in the right order?/could I condense functions anywhere?/should my image and sound be listed in both setup and draw as they are?) and I’m guessing it’s causing me some inflexibility as I try to work in new code to this project:
let img;
let song;
function windowResized()
{
resizeCanvas(windowWidth, windowHeight);
}
function preload()
{
img = loadImage('assets/picture.png');
song = loadSound('assets/recording.m4a');
}
function setup()
{
var cnv = createCanvas(windowWidth, windowHeight);
cnv.style('display', 'block');
imageMode(CENTER);
img = loadImage('assets/picture.png');
song = loadSound('assets/recording.m4a');
frameRate(12);
}
function mousePressed()
{
getAudioContext().resume()
song.play();
}
function mouseMoved()
{
song.play();
}
function touchStarted()
{
getAudioContext().resume()
song.play();
}
function touchMoved()
{
song.play();
}
function draw()
{
var mX=mouseX
var mY=mouseY
image(img, mX, mY, img.width / 2,
img.height / 2);
}