sifon Posted May 12, 2015 Share Posted May 12, 2015 Hello, I want to take control of the canvas the game is rendered but when I specify the element ID to Phaser.Game parameter, it is creating a new canvas inside it. If I have this: <div id="taskContainer"></div>And I do this: new Phaser.Game(200, 400, Phaser.AUTO, "taskContainer");Phaser is creating the canvas and adding to the div like this: <div id="taskContainer"> <canvas></canvas> </div>OK, but I want to specify the canvas, if I have this: <div> <canvas id="taskContainer"></canvas> </div>With the same code, Phase is doing this crazy thing: <div> <canvas id="taskContainer"> <canvas></canvas> </canvas> </div>How can I say to Phaser I want to use the canvas I'm setting by itself and not as a parent container??? Thanks!! Link to comment Share on other sites More sharing options...
drhayes Posted May 12, 2015 Share Posted May 12, 2015 Do you need to create the canvas yourself? If not, the canvas is available at Phaser.Game#canvas. If you do need to create it yourself instead of modifying it after Phaser makes it, I bet you could instantiate the Game then re-assign the canvas and context properties. Link to comment Share on other sites More sharing options...
sifon Posted May 12, 2015 Author Share Posted May 12, 2015 Yes, I need to create the canvas by myself. How can I do what you say? Can you please give me an example? Thanks! Link to comment Share on other sites More sharing options...
drhayes Posted May 12, 2015 Share Posted May 12, 2015 I don't know that this will work. Let's say you already have a reference to the canvas, maybe from document.getElementById or wherever.var game = new Phaser.Game(640, 480, Phaser.CANVAS);game.canvas = canvas;game.context = canvas.getContext('2d');¯\_(ツ)_/¯ Link to comment Share on other sites More sharing options...
sifon Posted May 12, 2015 Author Share Posted May 12, 2015 Maybe it should work, I will try, but that way Phaser is creating a canvas and then rewriting it, is bad for performance.Is not possible to tell Phaser "ey dude, this is the canvas I have for you, don't create one!"? Is a pity! Link to comment Share on other sites More sharing options...
drhayes Posted May 12, 2015 Share Posted May 12, 2015 Nah, it's not bad for performance to make one HTML element and then delete it. I wouldn't worry about it. Why do you need a custom canvas? Link to comment Share on other sites More sharing options...
Recommended Posts