I've been doing a simple program, which simulates someone throwing an object. Everything appears to work, but... I want to execute one loop per ~100ms.
button.addEventListener("click", function(){
for(let i = bob_x; i < 1504; i++){
setTimeout(function(){
pos_x = i;
//console.log("vx: " + vx);
//console.log("vy: " + vy);
//console.log("i: " + i);
//console.log("G: " + G);
pos_y = vy/vx*i - G*i*i/2/vx/vx;
obj.style.setProperty("left", pos_x);
obj.style.setProperty("top", parseInt(pos_y, 10));
}, 100)
}
})
It doesnt wait and executes everything in about quarter a second. I dunno why.
vx and vy here are coordinates of a vector, made by subtracting coordinates from eventlistener "mouseup" from coordinates from event "mousedown". Bob_x is the x-coordinate of a block representing a guy.