我有一个递归功能,可以在画布上移动一些圆圈.被遮挡的圆圈被放大(放大),所有其他圆圈被推开.推动圆圈推动其他圆圈,依此类推,直到缩放完成.
我得到一个错误"超出最大调用堆栈大小",我理解这个问题,但我只是不知道如何解决它...我找到了三种解决递归问题的可能解决方案:
但我认为我不能使用它们:
我该如何解决这个问题?
// Pushes circles aside when some other circle leans on these circles (on zoom in)
var moveCirclesAside = function(circle1, circleToSkip, groupOfMoves) {
var count = circles.length;
for (var i = 0; i < count; i++) {
// Skip the same circle
if (i == circle1.i) {
continue;
}
// Also skip the circle which was intended not to move any further
if (circleToSkip != null && i == circleToSkip.i) …Run Code Online (Sandbox Code Playgroud)