Jump to content

game.physics.p2.useElapsedTime = true;


noobshit
 Share

Recommended Posts

create()
    {
        game.physics.startSystem(Phaser.Physics.P2JS);
        game.physics.p2.useElapsedTime = true;
        game.physics.p2.setImpactEvents(true);

        ...
    }

 

        // On shotgun shell shot
        game.time.events.add(Phaser.Timer.QUARTER * 3, this.split, this);

I expected to get split at constant distance from space but it's depends on framerate. How to make time event in P2 timer?

https://noobshit.github.io/ - here is example of problem (cursors to move, space to shoot)

Link to comment
Share on other sites

    /**
    * Internal P2 update loop.
    *
    * @method Phaser.Physics.P2#update
    */
    update: function () {

        // Do nothing if the physics engine was paused before
        if (this.paused)
        {
            return;
        }

        if (this.useElapsedTime)
        {
            this.world.step(this.game.time.physicsElapsed);
        }
        else
        {
            this.world.step(this.frameRate);
        }

    },

    /**
    * @property {number} frameRate - The frame rate the world will be stepped at. Defaults to 1 / 60, but you can change here. Also see useElapsedTime property.
    * @default
    */
    this.frameRate = 1 / 60;

https://github.com/photonstorm/phaser/blob/v2.5.0/src/physics/p2/World.js#L66

 

https://github.com/photonstorm/phaser/blob/v2.5.0/src/time/Time.js#L119

 /**
    * The physics update delta, in fractional seconds.
    *
    * This should be used as an applicable multiplier by all logic update steps (eg. `preUpdate/postUpdate/update`)
    * to ensure consistent game timing. Game/logic timing can drift from real-world time if the system
    * is unable to consistently maintain the desired FPS.
    *
    * With fixed-step updates this is normally equivalent to `1.0 / desiredFps`.
    *
    * @property {number} physicsElapsed
    */
    this.physicsElapsed = 1 / 60;

    /**
    * The physics update delta, in milliseconds - equivalent to `physicsElapsed * 1000`.
    *
    * @property {number} physicsElapsedMS
    */
    this.physicsElapsedMS = (1 / 60) * 1000;

So basically if this.useElapsedTime is true it uses frameRate == 1/60, if not it uses physicsElapsed == 1/60. No matter what useElapsedTime is set it will use 1/60.

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