Posted May 28, 2019 by rymdkraftverk
#PixiJS #performance #javascript
Tails is run in the browser using PixiJS (a wrapper library for WebGL). Rendering performance proved to be a challenge. We went into the project thinking that performance would not be an issue. After all, our game was not to be graphically advanced, so there was probably no need to focus on optimising performance. That turned out to be very wrong.
There are a lot of things you need to be mindful of, even if your game doesn’t seem to be advanced. We strongly recommend that you follow the advice in the wiki. When you work with WebGL you want the number of “draw calls” to be as low as possible. We managed to go from more than 1000 draw calls to just a single one, following that guide.
The snakes are rendered as lots of tiny Pixi sprites. Every other game update, the “head” will drop a “tail” sprite in its current location. This means that in the end of every round we might have more than 10 000 sprites in play at the same time. And that’s what caused the game to lag in certain situations.
Some general advice:
We preload the textures with Pixi’s built- in resource loader. Here is a code snippet that we use to easily get the textures in our code:
https://gist.github.com/sajmoni/300d65e73ff8cc658ffdfb257b0722aa
This function (and more) is also available in a utility library for Pixi we made:
https://github.com/rymdkraftverk/level1
/ Rymdkraftverk