How to use PIXI.Application() when there is already a canvas element in HTML?
See original GitHub issueGood evening,
my issue is not a bug, but more my difficulty to understand the documentation.
I am using pixi.js version 5.2.0 to create a word app at Facebook and your library is great, thank you all very much for developing it.
However recently I have migrated my code from pixi.js 4 to 5 and I am not sure how to change my code:
var ratio = BOARD_WIDTH / (BOARD_HEIGHT + SmallTile.HEIGHT);
var renderer = new PIXI.Renderer({
width: BOARD_WIDTH,
height: BOARD_HEIGHT + SmallTile.HEIGHT,
view: document.getElementById('board')
});
window.onresize = function(event) {
var w = Math.min(window.innerWidth, screen.width) - 2 * MENU_WIDTH;
var h = Math.min(window.innerHeight, Math.round(.7 * screen.height));
if (w / h >= ratio) {
w = Math.round(h * ratio);
} else {
h = Math.round(w / ratio);
}
renderer.view.style.width = (w - 2 * PADDING) + 'px';
renderer.view.style.height = (h - 2 * PADDING) + 'px';
};
window.onresize();
My problem is that the v5 doc suggests:
const app = new PIXI.Application();
// The application will create a canvas element for you that you
// can then insert into the DOM
document.body.appendChild(app.view);
But I already have a canvas element in my HTML file:
<TABLE WIDTH="100%"><TR>
<TD ALIGN="center"><CANVAS ID="board" STYLE="border: 1px dotted white;"></CANVAS></TD>
</TR></TABLE>
How can I please use the new PIXI.Application, but attach it to the existing canvas element?
As you see probably see from my code I am not very proficient in the latest Javascript syntax, but I think my issue is very simple, I am just missing some guidance. Thank you.
Environment
pixi.js
version: 5.2.0- Browser & Version: Opera
- OS & Version: Win 10
- Running Example: https://apps.facebook.com/slova-farbera/
Here the error reported by some of my game users (using Opera browser or maybe Yandex browser - the communication with the user is challenging, she is an elderly lady):
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top GitHub Comments
Do something like you were doing in v4, pass the
view
option to the Application constructor:Check out the docs: http://pixijs.io/docs
Pixi (pixi legacy) must automatically detect supported renderer (‘forceCanvas:false’) when you use Application.
If it isn’t true, it is bug.