Jump to content

how to user pixi timer or eventemitter?


rossi46
 Share

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??

Link to comment
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

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...