Canvas Pixi JS和背景渐变
我试图在画布上添加背景,但似乎无法这样做Canvas Pixi JS和背景渐变,canvas,html5-canvas,pixi.js,Canvas,Html5 Canvas,Pixi.js,我试图在画布上添加背景,但似乎无法这样做 // create a renderer instance var renderer = PIXI.autoDetectRenderer(W, H); // add the renderer view element to the DOM document.body.appendChild(renderer.view); var canvas = renderer.view; // This returns the canvas DOM element
// create a renderer instance
var renderer = PIXI.autoDetectRenderer(W, H);
// add the renderer view element to the DOM
document.body.appendChild(renderer.view);
var canvas = renderer.view; // This returns the canvas DOM element
var ctx = canvas.getContext('2d');
console.log (ctx); //This returns null
有没有关于我做错了什么的想法?因此,虽然上面的评论中有答案,但我想我应该突出显示答案
使用AutoDetectTrender返回WebGLRenderer。显式地将渲染器设置为CanvasRenderer提供了对上下文对象的访问。因此您想知道为什么webGL渲染器在默认情况下不使用Context2D进行渲染。嗯,哎呀,我指定它使用canvas,结果它成功了。谢谢哈哈,完全忽略了这一点