Hi,
I’m reading this article right now:
In the section A simple character animation
there is a block of code:
if(posX > width/2) {
newStartPos = -((width/2) + 102);
posX = Math.ceil(newStartPos / 13) * 13;
console.log(posX);
} else {
posX += 2;
}
I don’t understard why we need this line:
posX = Math.ceil(newStartPos / 13) * 13;
and we cant just replace it with:
posX = Math.ceil(newStartPos);
It’s written below the code that:
“This has to be a multiple of 13 because otherwise the previous code block won’t work, since posX
would never equal a multiple of 13!”
but if we take any whole number and add 2 to it in each iteration it will eventually be a multiple of 13…