Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

rectangle fade


sergil
 Share

Recommended Posts

I made a fadein+fadeout effect between states (using a function that uses a black sprite that changes the alpha), but I was thinking if this approach can be done using a rectangle object fill of black color??? how could be done?

 

my actual code is:

fade: function (nextState)     {        var spr_bg = this.game.add.sprite(0, 0, "black-bg");        spr_bg.alpha = 0;        this.nextState = nextState;        s = this.game.add.tween(spr_bg)        s.to({ alpha: 1 }, 500, null)        s.onComplete.add(this.changeState, this)        s.start();    },    changeState: function ()     {        this.game.state.start(this.nextState);        this.fadeOut();    },    fadeOut: function ()     {        var spr_bg = this.game.add.sprite(0, 0, "black-bg");        spr_bg.alpha = 1;        s = this.game.add.tween(spr_bg)        s.to({ alpha: 0 }, 700, null)        s.start();    },

Rich, if you are tweaking the state management for the new version of phaser, could be interesting to include some basic transition effects between states?

Link to comment
Share on other sites

ok I finally used:

fade: function (nextState)     {        var spr_bg = this.game.add.graphics(0, 0);        spr_bg.beginFill(this.fadeColor, 1);        spr_bg.drawRect(0, 0, this.game.width, this.game.height);        spr_bg.alpha = 0;        spr_bg.endFill();        this.nextState = nextState;        s = this.game.add.tween(spr_bg)        s.to({ alpha: 1 }, 500, null)        s.onComplete.add(this.changeState, this)        s.start();    },    changeState: function ()     {        this.game.state.start(this.nextState);        this.fadeOut();    },    fadeOut: function ()     {        var spr_bg = this.game.add.graphics(0, 0);        spr_bg.beginFill(this.fadeColor, 1);        spr_bg.drawRect(0, 0, this.game.width, this.game.height);        spr_bg.alpha = 1;        spr_bg.endFill();        s = this.game.add.tween(spr_bg)        s.to({ alpha: 0 }, 600, null)        s.start();    },

I have a variable this.fadeColor to pass the color of the fade

 

Thanks a lot!!!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...