Jump to content

1.1.6 Animations not playing from key onDown callback


srobertson421
 Share

Recommended Posts

I'm having issues with the callback passed in to the onDown. For some reason when I try to play an animation from within the callback the animation won't play at all. What's strange is the animation will play fine in my key detection in the "update" function. My code is this:

 

 

Player = function(game) {    this.game = game;    this.sprite = null;    this.cursors = null;};Player.prototype ={        preload: function() {        this.game.load.spritesheet('grandpa', 'assets/grandpa.png', 64, 117);    },    create: function() {            this.sprite = game.add.sprite(2 * 64, 8 * 64, 'grandpa');             // animations        this.sprite.animations.add('left', [7,6,5,4], 7, true);        this.sprite.animations.add('right', [0,1,2,3], 7, true);        this.sprite.animations.add('up', [8,9,10,11], 7, true);        this.sprite.animations.add('down', [0,1,2,3], 7, true);        this.sprite.animations.add('beer', [0,12,13,0], 7, true);                this.cursors = this.game.input.keyboard.createCursorKeys();                var beerButton = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);                beerButton.onDown.add(beerDrink, this);                function beerDrink() {            console.log('beer!');            this.sprite.animations.play('beer');        }    }}

 

Link to comment
Share on other sites

I am currently developping a webapp ( http://mmmelee.herokuapp.com/ try it with 2 computers, it's online), and I have the same problem (with the callback function line 142 from socket.io). I think it could be because the function isn't in the "update" method. I would also be glad if someone has the solution...

 

EDIT : When i say from socket.io, I mean the function in the index socket.on. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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