rossi46

how to user pixi timer or eventemitter?

Recommended Posts

2 hours ago, ivan.popelyshev said:

Actually, according to the source code, it has to work with 4.5.3 . Just use "PIXI.tickers.shared" or "app.ticker" (if you have application like in pixi-examples), add the timer handler there.

i've just tried pixi 4.5.3. it didn't work. i say  "Cannot read property 'update' of undefined", but when i use pixi 3.0.8, it works. I use file pixi-timer.js in plugin. I use many timer in game. ticker can replace for setTimeout??

Share this post


Link to post
Share on other sites
4 hours ago, ivan.popelyshev said:

Give me a snippet of your code, how did you register the handler.

I use original example of pixi-timer.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Pixi.js Test</title>
  <script src="https://pixijs.download/v4.5.3/pixi.min.js"></script>
  <script src="js/pixi-timer.js"></script>
</head>
<body>
  <script>
    var renderer = new PIXI.autoDetectRenderer(800,600);
    document.body.appendChild(renderer.view);
    var stage = new PIXI.Container();

    function animate(){
      window.requestAnimationFrame(animate);
      renderer.render(stage);
      PIXI.timerManager.update();
    }

    animate();

    var timer = PIXI.timerManager.createTimer(1000);
    timer.repeat = 15;
    timer.on('start', function(elapsed){console.log('start')});
    timer.on('end', function(elapsed){console.log('end', elapsed)});
    timer.on('repeat', function(elapsed, repeat){console.log('repeat', repeat)});
    //timer.on('update', function(elapsed, delta){console.log('update',elapsed, delta)});
    timer.on('stop', function(elapsed){console.log('stop')});
  </script>
</body>
</html>

it doesn't run. 

Untitled-2.jpg

Share this post


Link to post
Share on other sites

Never use ".min.js" unless you are ready for production.

OK found this line: https://github.com/Nazariglez/pixi-timer/blob/master/src/Timer.js#L1 

The project built with browserify and somehow it doesnt see PIXI. I dont know what to do in that case, its JS problem. You have to clone it and debug what's wrong, or may be remove all "import/export". The least - you can build it without minification, and find the line in compiled js file that isnt working.

I'm sorry, that author chose ES6 with browserify. It has side effects.

Share this post


Link to post
Share on other sites
On 6/30/2017 at 5:36 AM, ivan.popelyshev said:

OK found this line: https://github.com/Nazariglez/pixi-timer/blob/master/src/Timer.js#L1 

The project built with browserify and somehow it doesnt see PIXI.

import PIXI from 'pixi.js';

Maybe try putting local copy of newest pixi.js in same source folder and see if you can rebuild pixi-timer.js? I'm not familiar enough to know how to build/bundle it with Browserify thou. Maybe better luck to open GitHub issue and ask its dev how to build for new Pixi release.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.