Giter VIP home page Giter VIP logo

phaser-state-transition's Introduction

State Transition Plugin for Phaser

npm version

About

Currently the switch between states is really static and a game should be able to transition between states. Therefore, this plugin does exactly that: draws the game.world into a renderTexture which is rendered on a sprite, and finally it's tweening that sprite.

Transition Examples

https://codepen.io/cristianbote/full/GjgVxg

How to use it

You have several options here including es6 imports.

Npm

npm install phaser-state-transition --save

And then import it in your project

import "phaser-state-transition";

The plugin needs the Phaser framework to work, therefore you should make sure that this is included before the plugin's import.

Straight but nor recommended

Just download the dist/phaser-state-transition.umd.js file and you're done, but this is not the recommended way. You should use it via npm. You have better control on what version you're keeping locally.

Usage

The easiest way to use it, is by just passing a transition for entering.

import { createTransition } from "phaser-state-transition";

const EnteringTransition = createTransition({
    props: {
        x: game => game.width
    }
});

game.state.start("stateName", EnteringTransition);

The transition options to pass in are basically just some instructions for the plugin, to handle the how of the transition. You'll find there are other properties inside, like ease, duration and other properties that are not that important to have nice transitions.

API

StateTransitionPlugin

The plugin class. Normally you should not work on this class, but you could extend it if needed. The plugin does not need a class to be working.

createTransition(options)

This helper function, generates a transition object to be passed along the game.state.start method.

The default duration would be 500ms and the ease function Phaser.Easing.Exponential.InOut

  • @param {object} options The options to create a transition object
  • @returns {object} The transition object to be passed along the game.start.state

Feedback

If there's something you think it could be improved let me know, or create a pr.

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.