Skip to content

netmute/impact-pause

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Pause plugin for ImpactJS

This was originally written by Jesse Freeman. I just cleaned it up a bit.

Usage

ig.module(
  'game.main'
)
.requires(
  'impact.game',
  'plugins.pause'
)
.defines(function(){
  MyGame = ig.Game.extend({

    init: function() {
      ig.input.bind( ig.KEY.P, 'pause' );
    },

    update: function() {
      if ( ig.input.state('pause') ) {
        this.togglePause();
      }
    }
  });
});

How does it work?

We're giving the impression of stopping the game by not calling update() on the entities currently present in the game.

You can override this behavior for individual entities by adding the ignorePause: true attribute to the entity.

SomeEntity = ig.Entity.extend({
    ignorePause: true
});

A note on timers

Since we're just skipping Entity.update(), all timers keep running while the game is paused. But sometimes you want certain timers to be stopped as well.

The plugin injects two hooks into ig.Game which you can use to fix this.

onPause: function() {
  yourTimer.pause();
},

onResume: function() {
  yourTimer.unpause();
}

About

A pause plugin for ImpactJS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published