Giter Club home page Giter Club 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.

phaser-state-transition's People

Contributors

cristianbote avatar nickryall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phaser-state-transition's Issues

Typescript definition updates ?

Hi,

I am using typescript and works great with phaser, but adding this I get errors saying that StateTransition doesn't exist.

        this.game.state.start('TestPhase',
            Phaser.Plugin.StateTransition.Out.SlideLeft,
            Phaser.Plugin.StateTransition.In.SlideLeft,
            true,
            false,
            true
        );

Of course, this is probably to be expected as the StateTransition is added onto the Phaser.Plugin

Right now it uses the index.d.ts which is available in typings/global/phaser

I was wondering how to extend this types file, without having to edit the original typings file ?

Also wondered if it's possible to create a new method to start the transition instead of adding it on the phaser.Plugin - this may potentially break in the future as Phaser modifies this file, or adds a StateTransition of its own :-)

Any ideas the best way to tackle this would be really helpful.

Thanks

Blank screen before transition

After I call transition, this happens when I have preloading in the next state:

  • The screen goes blank for 500ms-2s
  • The sprites of the current state re-appears
  • Then the transition animation happens.

If I remove the preloading in the next state, it's working fine without any interruption.
Could you advice how to fix this?

freezes on the end of the transition on iphone 6

Hi,

great plugin but when I tested it with phaser 2.2.2 and iphone 6 safari. tried different devices and only the iphone 6 had this issue, it froze at the end of the transition, I guess the sprite it transitions in does not hide. Anyhow, I am going to test it with phaser 2.3. Would be cool if you could have a look at this.

Greetz and thx

Feedback needed

Hi there,

So, I'm thinking of rewriting this plugin, completely, but I need feedback, from real world users.

  1. How do you use it on real games?
  2. What needs to be improved?
  3. What's missing?
  4. Is it helpful?

I'm grateful for your answers!

Cheers!

Persistent Sprites Hidden behind background in Snapshot

I'm using the stage to keep a persistent background across states, however, as I started using this plugin, the snapshot it takes moves the screen with a background (black as default since it's set to transparent in phaser). Note that after transition is done, the background stays in place.

Is there anything that can be done about this?

For reference, I'm setting the background with game.stage.addChildAt(backgroundSprite,0);

Add list of transitions

I would like to request a list of default available transitions.

If they could include a .gif showing off the result it would benefit the user and the plugin greatly. Just a suggestion.

Thanks for this!

Unable to use .js

The latest .js file is giving me error when included:

Uncaught ReferenceError: module is not defined
    at phaser-state-transition.js:1

Transition does not care about camera position

I have a state where I move the camera in the create function. However when the transition to this state happens, it uses a snapshot taken at coordinates (0,0) regardless of the camera.

It looks like it was well done previously, but the code added for Phaser 2.4.8+ is wrong :

https://github.com/cristianbote/phaser-state-transition/blob/master/src/core/ContentSnapshot.js#L34

this._texture.renderXY(game.world, 0, 0);

should be replaced with

this._texture.renderXY(game.world, -game.camera.position.x, -game.camera.position.y);

state "create" method being called twice when using "In" transition

When I pass in the optional In transition, the create method is being called twice. Just wondering if this is intended, as it seems like it might be unnecessary.

How I'm calling:
game.state.start('MainMenu', Phaser.Plugin.StateTransition.Out.SlideRight, Phaser.Plugin.StateTransition.In.SlideRight);

Screen blinking upon transition

I'm building a physics based application, that doesn't have any external plugins except for admobpro.
Do I need to terminate something in the current state before proceeding to the next to avoid the blinking?

I added an event listener that calls a function when I click on a button, the function is the following:

game.state.start('maingame',Phaser.Plugin.StateTransition.Out.SlideRight, Phaser.Plugin.StateTransition.In.SlideRight);

Of course I have preloaded the 'maingame' state.

The screen blinks and turns black for a moment then does the transition. I've heard that other transition plugins somehow interfered with different plugins on the same project thus causing the blink, but I doubt an admob plugin will do any trouble with that..

Misplaced sprites and groups after state transition

Referencing the conversation started here #16 (comment) I discovered the issue was somehow related to group's top/bottom properties breaking when using state transitions. You can see the commit with the workaround here.

state transitions are working, turns out some_group.top/bottom is somehow broken due to them. If you use some_group.y to set y position instead it will work. To test this, run the current code with state transitions: it works. Then, set groupTopAndBottomPropertiesAreMessedUp on line 73 of the Store state to false. After a few Store>Game>Store transitions the Store state will break (because top/bottom properties are used). Finally remove state transitions by going to the Preload state, commenting out line 13 (the import), line 40, and line 44 (state transition getters). Uncomment lines 39 and 43 (now they are state.start parameter functions). Set groupTopAndBottomPropertiesAreMessedUp to true or false, they both work.

Want to use default state parameter

Hello, I want to use Phaser default state parameter like this mystate1.start(mystate2, clearWorld, clearCache, parameter) but remember I also want to smooth transition so I have added this
mystate1.start('mystate2', Phaser.Plugin.StateTransition.Out.SlideBottom);

So How can I clear cache and pass parameter ?

How to disable anti-aliasing during transition?

I'm working on a game with pixel art where anti-aliasing is disabled. All of my assets are scaled 2x. They all look crisp until a state transition starts; they are blurry during the transition, and when the transition is over, they go back to being crisp again. Is there a way to ensure that the state transition plugin doesn't try to anti-alias my assets?

Game is here: http://montoyaindustries.com/spin/

Tap the gear icon to see the title turn blurry.

[Question] Need help to use this plugin

Hello, I have read readme file but I can not understand how to use this plugin, I added my states in Boot.js file and imported 'phaser-state-transition.min.js' file inside index.html so when I tried to start my states like this 'game.state.start('playState', [outTransition, [inTransition]]);' it shows some error in console.
Please help me to use this plugin I know it will be a great experience.

Jornhill Behavior Change?

I know it just dropped, but might as well make it known:

It seems in 2.0.6 the behavior of the scene rendering has changed. Rather than "taking the picture" of the last scene, then doing the fade/animation, it seems to turn into a solid color instead (then fade/animate).

Limit of 1 state transition per phaser project

One state transition is far better than none however I suggest allowing multiple transitions per project.

For example, I have often animated a help screen in one way and then back out in a different way, often exactly the opposite of the way it was animated in. This is to emphasize the player's return to the previous screen (back to the title or game screen). This requires two different state transitions.

Thank you for putting this project up, it is excellent!

Starting a transition while a transition is running creates a ghost snapshot

If you start a transition while a transition is already running, there is a ghost snapshot that doesn't disappear properly. Here is an example :

https://jsfiddle.net/Owumaro/a9xvn1jb/5/

I have 3 states that start in cycle (1, 2, 3) by pressing the enter key. The transition lasts 1 second, so you can easily hit enter while a transition is already running.

It looks like the end snapshot of the 1st transition goes on top at the end of the 2nd transition.

Codepen examples

Hi man,

What do you think to create examples in Codepen? ๐Ÿ‘ฏ

Regards, Nicholls

Game Reversed

Hi,
When I use this lib. with _Phaser v2.2.1_ it work fine but it reverse the game !!.
how I can solve this issue.
Thank you.

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.