0
我嘗試使用下面的腳本添加一個圓圈內的圖像:動力學JS圖像調用setVisible
....
var rCvisible = false;
...
var rC = new Image();
rCircle;
rC.onload = function() {
rCircle = new Kinetic.Image({
image: rC,
opacity: 0.3,
visible: rCvisible
});
};
rC.src = '../../Content/images/rotate.png';
var circle2 = new Kinetic.Circle({
drawFunc: function (canvas) {
var context2 = canvas.getContext();
centerX2 = blueLine2.getPosition().x;
centerY2 = greenLine2.getPosition().y;
context2.drawImage(rC, centerX2 - 20, centerY2 - 20, 44, 40);
context2.beginPath();
context2.arc(centerX2, centerY2, this.getRadius(), 0, 2 * Math.PI, false);
context2.lineWidth = this.getStrokeWidth();
context2.strokeStyle = this.getStroke();
context2.stroke();
},
x: cx + gx,
y: cy + gy,
radius: 70,
stroke: '#00ffff',
strokeWidth: 3,
opacity: 0.5
});
.....
circle2.on('mouseover', function() {
document.body.style.cursor = 'pointer';
rCvisible = true;
layer2.draw();
});
circle2.on('mouseout', function() {
document.body.style.cursor = 'default';
rCvisible = false;
layer2.draw();
});
我也試過:
context2.drawImage(rC, centerX2 - 20, centerY2 - 20, 44, 40, setVisible(false));
我的目標是隱藏圖像,然後再顯示它當鼠標在圓圈內時。 我得到了follwing錯誤:
'setVisible' is undefined
會感激你的建議,在此先感謝。
感謝馬克,非常好的替代方法。 – hncl
我也想出了這個替代方案,如果(rCvisible){context2.drawImage(rC,centerX2-20,centerY2-20,44,40);}它的效果很好。再次感謝你的幫助。 – hncl