nonamedude Posted September 16, 2014 Share Posted September 16, 2014 Hey guys, I'm new to pixi.js and canvas. I've been trying to add a gradient to the background but I can't seem to get the context (returning null). What am I doing wrong ?var renderer = PIXI.autoDetectRenderer(window.innerWidth, window.innerHeight); // add the renderer view element to the DOMdocument.body.appendChild(renderer.view);var canvas = renderer.view;var ctx = canvas.getContext('2d');console.log (ctx); //null As a result this will not workvar lingrad = ctx.createLinearGradient(0,0,0,150); Quote Link to comment Share on other sites More sharing options...
rich Posted September 16, 2014 Share Posted September 16, 2014 If you want to do context operations then you need to use the CanvasRenderer and not autoDetect, because that has given you a WebGL context, which you can't draw to in the way you're trying to. Quote Link to comment Share on other sites More sharing options...
Sebi Posted September 16, 2014 Share Posted September 16, 2014 To add to rich's answer:To create a gradient you can use any canvas that is not running on a webgl context. You are not forced to use PIXI's CanvasRenderer just to use canvas methods. var canvas = document.createElement('canvas');var ctx = canvas.getContext('2d'); Then create your gradient on that canvas and use it as a Texture for your background Sprite. Quote Link to comment Share on other sites More sharing options...
nonamedude Posted September 16, 2014 Author Share Posted September 16, 2014 Yep I see what you mean. Got it to work . Thanks guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.