2014-03-19 23 views
0

我正在嘗試在線網頁遊戲。 我希望能夠在畫布內產生一個立方體,當你將它放在畫布上時,我希望它被移除。KineticJS將鼠標移到畫布上刪除

我在JavaScript中的newcorner但是這是我到目前爲止的代碼

var stage = new Kinetic.Stage({ 
     container: 'gamebox', //Find an HTML element 
     width: 553, 
     height: 498 
    }); 

    var layer = new Kinetic.Layer(); // Don't know what this shit is doing 

    var numEvents = 0; 

    var rect = new Kinetic.Rect({ // Create a cube 
     x: 239, 
     y: 75, 
     width: 50, 
     height: 50, 
     fill: 'green', 
    }); 

    rect.on('mouseover mousedown mouseup', function() { 
     numEvents=++numEvents; 
     document.getElementById("energycollector").innerHTML=numEvents; 
     context.clearRect (239 , 75 , 50 , 50); 
    }); 

    // add the shape to the layer 
    layer.add(rect); 
    // add the layer to the stage 
    stage.add(layer); 

回答

0

context.clearRect在HTML5畫布用於覆蓋在畫布上的一部分,但使用KineticJS時,它並不適用。

在KineticJS,您的矩形是一個對象,所以你會刪除RECT這樣的:

// to remove the rect, but not destroy it (you could later re-add it to the layer) 

rect.remove(); 

// OR, to remove and destroy the rect 

rect.destroy() 

祝你遊戲!