Jump to content

how to know when and action finished


sergil
 Share

Recommended Posts

Hi!
 
I'm new in this forum and phaser ... I'm also remembering how to use javascript as it took a long time without using it
 
for the development of my little test game, I'm using the dev branch of phaser and examples of gamestate .. I encounter a problem when wanting to control when a tweening is complete.
 
so, when I want to control when the tween has finished and the game can start playing, I find that chrome gives me the exception "is a required param listener of add () and Should be a Function"
Test.Game = function (game) {        this.game = game;        this.messageLayer;        this.play = false;};Test.Game.prototype = {        preload: function () {                this.game.load.spritesheet('balls', 'assets/sprites/balls.png', 17, 17);        },        create: function () {                                this.messageLayer = this.game.add.group();                this.GUImessageStart();        },        update: function () {                if (this.play) {                        //this.updateGame();                        //this.updateScore();                }                        },        GUImessageStart: function () {                var spr_menu = this.game.add.sprite(-this.game.width/2, this.game.world.centerY, 'message');                spr_menu.anchor.setTo(0.5, 0.5);                this.game.add.tween(spr_menu)                .to({ x: this.game.width/2 }, 1500, Phaser.Easing.Bounce.Out)                .to({ x: this.game.width+(this.game.width/2) }, 500, Phaser.Easing.Linear.None, false, 1000)                .onComplete.add(this.startPlay(), this)                .start();                this.messageLayer.add(spr_menu);        },        startPlay: function () {                this.play = true;        },        quitToMenu: function () {                console.log('lets quit! back to the main menu');                this.game.state.start('mainmenu');        }}
do you know what is happening and how to fix it?
 
Thanks in advance

 

 

Link to comment
Share on other sites

Yes, but I think you'll find it may still not work, because I don't think onComplete.add returns the tween data type, so the chain will break. Best to just have that on a line on its own. Very few functions in Phaser support chaining, so it's probably not a safe habit to get in to using, as it'll break all over the place if tried elsewhere.

Link to comment
Share on other sites

I found the problem... the final code is 

s = this.game.add.tween(spr_menu)s.to({ x: this.game.width/2 }, 1500, Phaser.Easing.Bounce.Out)s.to({ x: this.game.width+(this.game.width/2) }, 500, Phaser.Easing.Linear.None, false, 1000)s.onComplete.add(this.startPlay, this)s.start();

I create a variable (like the examples of phaser) for controling tween and I't works...

 

thanks

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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