Hey, glad it helped!
In your first version, circleX was a global var, that means it was shared by all circles.
That means
- all circle had the same x-position and
- not individual x-positions and
- that the decrease in the position (
- speed) was 10 times per frame executed (hence the circles got so fast!) and not only once (when circleX is in the class, it’s an object property, so there are 10 individual values and the speed is subtracted only once from each circleX per frame, not 10 times).
When circleX is inside the class, we achieve
- individual values for each circle
- speed is subtracted only once per frame (so it’s slower).
Warm regards, Chrisir