Jump to content

Anyone familiar with Proton.js?


Gyldstrand
 Share

Recommended Posts

I was trying to hook up http://www.a-jie.cn/proton/example/render/custom/pixijs.html to my project.

 

    var proton;
    var emitter;

    function Main() {
        createProton();
        createRender();
        tick();
    }

    Main();

    function createProton() {
        var texture = PIXI.utils.TextureCache["image/fire.png"];
        proton = new Proton();
        emitter = new Proton.BehaviourEmitter();
        emitter.rate = new Proton.Rate(new Proton.Span(15, 30), new Proton.Span(.2, .5));
        emitter.addInitialize(new Proton.Mass(1));
        emitter.addInitialize(new Proton.ImageTarget(texture));
        emitter.addInitialize(new Proton.Life(2, 3));
        emitter.addInitialize(new Proton.Velocity(new Proton.Span(3, 9), new Proton.Span(0, 30, true), 'polar'));

        emitter.addBehaviour(new Proton.Gravity(8));
        emitter.addBehaviour(new Proton.Scale(new Proton.Span(1, 3), 0.3));
        emitter.addBehaviour(new Proton.Alpha(1, 0.5));
        emitter.addBehaviour(new Proton.Rotate(0, Proton.getSpan(-8, 9), 'add'));
        emitter.p.x = 1003 / 2;
        emitter.p.y = 100;
        emitter.emit();
        proton.addEmitter(emitter);

        emitter.addSelfBehaviour(new Proton.Gravity(5));
        emitter.addSelfBehaviour(new Proton.RandomDrift(30, 30, .1));
        emitter.addSelfBehaviour(new Proton.CrossZone(new Proton.RectZone(50, 0, 953, 610), 'bound'));
    }

    function createRender() {
        var renderer = new Proton.Renderer('other', proton);
        document.body.appendChild(renderPIXI.view);
        renderer.onProtonUpdate = function() {

        };

        renderer.onParticleCreated = function(particle) {
            var particleSprite = new PIXI.Sprite(particle.target);
            particle.sprite = particleSprite;
            stage.addChild(particle.sprite);
        };

        renderer.onParticleUpdate = function(particle) {
            transformSprite(particle.sprite, particle);
        };

        renderer.onParticleDead = function(particle) {
            stage.removeChild(particle.sprite);
        };
        renderer.start();
    }

    function transformSprite(particleSprite, particle) {
        particleSprite.position.x = particle.p.x;
        particleSprite.position.y = particle.p.y;
        particleSprite.scale.x = particle.scale;
        particleSprite.scale.y = particle.scale;
        particleSprite.anchor.x = 0.5;
        particleSprite.anchor.y = 0.5;
        particleSprite.alpha = particle.alpha;
        particleSprite.rotation = particle.rotation*Math.PI/180;
    }

    function tick() {
        proton.update();
        renderPIXI.render(stage);
    }

    tick();

 

I got rid of all the errors but nothing is displaying. I have this put inside the game loop.

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