嘿伙计们,我已经被这个问题困扰了 2 天。我似乎无法让这段代码工作:http ://www.taffatech.com/Paint.html 绘制 3 个点,单击 2 次撤消,它会按预期进行,所以我希望它不会太多使固定。我将撤消重做绑定到 2 个按钮“撤消”和“重做”,它们在这里:
-更新,这可能更有意义?我得到了它的工作,除了它现在删除两个然后它通常 1 比 1
function clearCanvas()
{
ctx.clearRect(0,0,canvasWidth,canvasHeight);
}
Stack1 = new Stack();
///////////////////
function Stack() {
var currentState = 0;
var maxStates = 10;
var stateArray = [];
var image = new Image();
image.id = "pic";
image.src = canvas.toDataURL();
stateArray.push(image);
this.add = function() {
var image = new Image();
image.id = "pic";
image.src = canvas.toDataURL();
stateArray.push(image);
currentState++;
}
this.undo = function () {
stateArray.pop();
currentState--;
clearCanvas();
var image = stateArray[curentState];
ctx.drawImage(image,0,0);
}
this.redo = function () {
alert("worry about later");
// if (stackIndex%stackSize == stackTop) return;
//clearCanvas();
//var tmpImg = new Image();
// tmpImg.src = drawStack[++stackIndex%stackSize];
// ctx.drawImage(tmpImg, 0, 0);
}
}