Jump to content

Attaching animation to game.time.events blocks previous animations


trpzn
 Share

Recommended Posts

I'm trying to build an animation manager to pack animations and launch each one at certain time.
example:
animation 1 launch,
animation 2 wait 300ms with game.time.events

Problem:
in pc the difference it's only visible in frame rate but in cellphone second animation stop first and seems very ugly.

code:
 

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });function preload() {    game.load.spritesheet('cthulhu', 'cthulhu.png', 700, 350);    game.load.spritesheet('scroll', 'scroll.png', 700, 350);    game.load.spritesheet('dead', 'dead.png', 700, 350);}function create() {        game.add.text(400,100,'Click to play and recharge animation');    game.input.onDown.add(playAnimations, this);    this.sprite1 = undefined;    this.sprite2 = undefined;    this.last = 1;}function playAnimations() {    console.log(this.sprite1);    console.log(this.last);    if(this.sprite1 != undefined){        this.sprite1.destroy();        this.sprite2.destroy();        this.sprite1 = undefined;        this.sprite2 = undefined;    }        this.sprite2 = game.add.sprite(0, 0, 'scroll');        this.sprite2.animations.add('walk', [0, 1, 2, 3, 4, 5]);    this.sprite2.animations.play('walk', 12, false,false);    if(this.last == 1){       game.time.events.add(                    200,                    function(){                        this.sprite1 = game.add.sprite(0, 0, 'cthulhu');                        this.sprite1.animations.add('walk', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],12,true);                        this.sprite1.animations.play('walk', 12, false,false);                    },                    this);    }else{        game.time.events.add(                    200,                    function(){                        this.sprite1 = game.add.sprite(0, 0, 'dead');                        this.sprite1.animations.add('walk', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],12,true);                        this.sprite1.animations.play('walk', 12, false,false);                    },                    this);    }        if(this.last == 1){        this.last = 2;    }else if(this.last == 2){        this.last = 1;    }}

I cant pack in atlas because i need one or more animations be playing at the same time, plus i have 20+ animations and jump between big atlas (8000*8000px) seems very laggy.

demo: demolink  (push to play anims)

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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