Giter Club home page Giter Club logo

phaser-capture's Introduction

Why?

Although each OS has their own set of tools for screenshots and video capture, I wanted something platform agnostic that I could simply plug into whatever web-based game I was making. This also lets me collect captures on computers that I don't have software installation rights on.

I chose Phaser in particular only because it's what I'm already using most of the time, but I would like to eventually include a more minimal module that does the core screenshot/recording work without being coupled to Phaser.

Usage

The plugin is packaged via UMD, meaning it'll work happily used if included browser globally (via <script src="phaser-capture.js">) or if you prefer Node or Browserify.

Unfortunately Phaser plugins are not very well documented, and most rely on their own ad-hoc documentation to instruct their users. For now, phaser-capture is no different:

// var PhaserCapture = require('phaser-capture');  // For Node/Browserify users

var playState = {
  create: function() {
    game.capture = game.plugins.add(Phaser.Plugin.Capture);
    // game.capture = game.plugins.add(PhaserCapture);  // Node/Browserify

    // Take a screenshot every 5 seconds.
    setInterval(function() {
      game.capture.screenshot(function(dataUrl) {
        // Outputs a data-url of the image (default image/png).
        console.log(dataUrl);
      });
    }, 5000);
  },
};

game = new Phaser.Game(800, 600);
game.state.add('play', playState);
game.state.start('play');

API

The resultant plugin exposes only one method currently:

screenshot(callback, opts)

  • callback is the function that will be called once the screenshot render is complete. It assumes its only argument will be a data-url.
  • options is an object that may contain:
    • format, either image/png or image/jpeg

/THE FUTURE!/

  1. Downloading screenshots easily
  2. Uploading screenshots somewhere (Dropbox? Something more agnostic?)
  3. Video recording! (GIF, WebM)

phaser-capture's People

Contributors

hackergrrl avatar

Watchers

Roman Murashov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.