我在調用我的方法drawInventory()時我的鼠標移動,當我按i。不透明度不應用JavaScript Canvas
我設置不透明度在drawInventory方法的開始:
function drawInventory() {
inventoryCtx.fillStyle = "rgba(0, 0, 0, 0.7)";
inventoryCtx.fillRect(10, 10, invWidth-20, invHeight-20);
}
當我移動鼠標,不透明度爲0.7保持正確的,但是按我後,不透明度降低。
這是我呼籲我的按鍵方法:
function toggleInventory() {
if(!showInventory) {
showInventory = true;
$("#inventoryCanvas").removeClass("hideClass");
drawInventory();
$("#inventoryCanvas").fadeIn(1);
}
else {
$("#inventoryCanvas").fadeOut(100);
showInventory = false;
}
};
奇怪的部分是,在第一時間刷新頁面,然後按我的不透明度後是存在的。如果我按兩次,則會返回更高的不透明度(較暗),然後下一次完全黑暗。我不知道爲什麼每次我調用同樣的方法時,它都會失去不透明性。
注意:我試過inventoryCtx.globalAlpha,它沒有改變這個問題。
任何幫助表示讚賞。
太棒了!您提供的那條簡單的代碼行解決了我的整個問題,謝謝。當我移動鼠標時,我正在調整它的大小,這就是爲什麼它不會導致問題出現。 – helpmeplease