Browse Source

Draw random lines, display FPS counter

Tyler Hallada 6 years ago
parent
commit
434578cebc
3 changed files with 25 additions and 0 deletions
  1. 20 0
      src/transport.js
  2. 4 0
      src/utils.js
  3. 1 0
      webpack.config.js

+ 20 - 0
src/transport.js

@@ -1,8 +1,28 @@
1 1
 import * as PIXI from 'pixi.js';
2
+import { randomInt } from './utils';
2 3
 import './style.css';
3 4
 
4 5
 const app = new PIXI.Application(window.innerWidth, window.innerHeight);
6
+const ticker = new PIXI.ticker.Ticker();
7
+const graphics = new PIXI.Graphics();
8
+const fpsText = new PIXI.Text('', { fontSize: '25px', fontFamily: 'monospace', fill: 'yellow' });
5 9
 
10
+fpsText.anchor = new PIXI.Point(1, 0);
11
+fpsText.x = window.innerWidth - 1;
12
+fpsText.y = 0;
13
+
14
+ticker.stop();
15
+ticker.add((deltaTime) => {
16
+  fpsText.setText(Math.round(ticker.FPS));
17
+  graphics.lineStyle(1, 0xaeaeae, 1);
18
+
19
+  graphics.moveTo(randomInt(9, window.innerWidth), randomInt(0, window.innerHeight));
20
+  graphics.lineTo(randomInt(9, window.innerWidth), randomInt(0, window.innerHeight));
21
+});
22
+ticker.start();
23
+
24
+app.stage.addChild(graphics);
25
+app.stage.addChild(fpsText);
6 26
 document.body.appendChild(app.view);
7 27
 
8 28
 window.addEventListener('resize', () => {

+ 4 - 0
src/utils.js

@@ -0,0 +1,4 @@
1
+export const randomInt = (min, max) => (
2
+  // inclusive of min and max
3
+  Math.floor(Math.random() * (max - (min + 1))) + min
4
+);

+ 1 - 0
webpack.config.js

@@ -42,6 +42,7 @@ module.exports = {
42 42
       filename: '[name].css',
43 43
     }),
44 44
   ],
45
+  devtool: 'cheap-module-eval-source-map',
45 46
   devServer: {
46 47
     contentBase: path.join(__dirname, 'dist'),
47 48
     host: '0.0.0.0',