cocos?creator里面將`cc.macro.ENABLE_TRANSPARENT_CANVAS`設(shè)為false時,也就是關(guān)閉canvas的alpha通道時,這個時候canvas背后的任何dom元素就不會去渲染了,原因已經(jīng)找到了,是瀏覽器自己做的優(yōu)化。?現(xiàn)在有一個辦法可以解決:用css設(shè)置canvas標(biāo)簽的opacity為0.999999或者將canvas縮放為0.99999倍,但這樣做不夠優(yōu)雅 ,有什么更好的辦法嗎(現(xiàn)在有一個功能要求canvas背后的dom必須正常渲染)下面是cocos creator官網(wǎng)對于 ENABLE_TRANSPARENT_CANVAS屬性的解釋用于設(shè)置 Canvas 背景是否支持 alpha 通道,默認為 false,這樣可以有更高的性能表現(xiàn)。 如果你希望 Canvas 背景是透明的,并顯示背后的其他 DOM 元素,你可以在?cc.game.run?之前將這個值設(shè)為 true。 僅支持 Webhttps://docs.cocos.com/creator/api/zh/classes/macro.html#enabletransparentcanvas下面是cocos creator的h5引擎中相關(guān)的部分源碼export?default?class?Device?{
/**
????*?@param?{HTMLElement}?canvasEL
????*?@param?{object}?opts
????*/
constructor(canvasEL,?opts)?{
let?gl;
//?default?options
opts?=?opts?||?{};
if?(opts.alpha?===?undefined)?{
opts.alpha?=?false;
}
if?(opts.stencil?===?undefined)?{
opts.stencil?=?true;
}
if?(opts.depth?===?undefined)?{
opts.depth?=?true;
}
if?(opts.antialias?===?undefined)?{
opts.antialias?=?false;
}
//?NOTE:?it?is?said?the?performance?improved?in?mobile?device?with?this?flag?off.
if?(opts.preserveDrawingBuffer?===?undefined)?{
opts.preserveDrawingBuffer?=?false;
}
try?{
gl?=?canvasEL.getContext('webgl',?opts)
||?canvasEL.getContext('experimental-webgl',?opts)
||?canvasEL.getContext('webkit-3d',?opts)
||?canvasEL.getContext('moz-webgl',?opts);
}?catch?(err)?{
console.error(err);
return;
}
}
//...
//...
}https://github.com/cocos-creator/engine/blob/c2223aba0949da0a54c0822a3632b90535ce038e/cocos2d/renderer/gfx/device.js
- 0 回答
- 0 關(guān)注
- 2123 瀏覽
添加回答
舉報
0/150
提交
取消