As a little break from my rhythm game I've been making with HTML/JavaScript, I decided to make a recreation of the Heatman bossfight from Megaman 2. I'm using setInterval to make the code loop infinitely. As a test, I made a function called moveHeat which adds 10 Heatman's left style value. When I run the setInterval with the function, the image (heatman) only moves once. What am I doing wrong?
Here is the code rn:
function moveHeat() {
document.getElementById("hetman").style.left += "10px";
return (document.getElementById("hetman").style.left)
}
var heatInterval = setInterval(function() {
moveHeat()
}, 10);
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
font-family: sans-serif;
}
#hetman {
position: relative;
left: 10px;
}
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<img src="https://via.placeholder.com/300" id="hetman">
</body>