Answers is deprecated.

Please use Forum to participate in community by asking and answering questions!

i'm running this code:

var TestCanvas = pc.createScript('testCanvas');

// initialize code called once per entity
TestCanvas.prototype.initialize = function() {
    var canvas = document.getElementById("application-canvas");
    var context = canvas.getContext("2d");
    if(context) {
        console.log("Got!");
    } else {
        console.log("nope!");
    }
};

And all I get is "nope!" Do I have to make my own canvas and size it to the same size as the application canvas? I even tried the above code in an update loop to see if i'm just not waiting long enough for it to load and i always get a null context.

asked 22 Dec '16, 22:27

rakberdin's gravatar image

rakberdin
5445
accept rate: 0%


So it turns out there is no 2d context because the browser is using webgl so i need to getContext("webgl")...

link

answered 22 Dec '16, 22:33

rakberdin's gravatar image

rakberdin
5445
accept rate: 0%

To get the WebGL context from PlayCanvas, just do: var gl = this.app.graphicsDevice.gl;

(22 Dec '16, 23:13) will ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×3

Asked: 22 Dec '16, 22:27

Seen: 662 times

Last updated: 22 Dec '16, 23:13

about | privacy | support | contact

playcanvas