Jump to content

on animationcomplete multiple callbacks per sprite ?


Recommended Posts

[edit at bottom but not completely solved to my liking]

I'm probably missing something silly but i'm pretty fresh to this, 


i did a search for "callback on specific animationcomplete phaser" but it gets me 1346 pages, apologies but i'm just gonna ask hoping someone picks up the phone :

i have one sprite named "chest" and one named "grabhand" 


i have a function called deathtrapcomplete() which does some camera stuff and restarts / resets the scene on gameover

now i have for grabhand :

this.anims.create({ key: 'traphand', frames : this.anims.generateFrameNumbers('grabhand', {start : 0, end: 29})


but for chest i have two :

this.anims.create({key: 'openchest' ....etc


this.anims.create({key 'chestsaysno' ... etc

i have an event for grabhand :


this.grabhand.on('animationcomplete', this.deathtrapcomplete, this); which does exactly what it should, it plays the anim completely and then starts the gameover sequence, ... very tidy, lol


when i use it for chest

this.chest.on('animationcomplete', this.deathtrapcomplete,this);

it triggers for both "openchest" and "chestsaysno" ... which is not so good as the former is simply an empty chest with a puff of dust coming out while the latter is a chest with a deadly trap (both from the same spritesheet)

So the question, how do i trigger it only for "chestsaysno" , defining two different sprites seems overkill and working around it in the call itself seems very in-elegant as the deathtrapcomplete() function is already there

It's hard to imagine i cant insert the specific animationkey in the on(...) handler somewhere so my guess is i simply can't find it as im pretty much a noob, on the docs it says "


string | symbol

but when i try this.chest.on('animationcomplete|chestsaysno' ... etc) it doesnt trigger anything at all (which is probably me not understanding what the pipe symbol means


thats why im asking , thanks a lot if anyone has time and patience to help me out here


about a minute after i find something on https://labs.phaser.io/edit.html?src=src/game objects\graphics\health bars demo.js where animation.key is used in the callback function so if i add


if(animation.key != 'openchest'){

...do gameover stuff..




it works but i still feel it would be better if i can simply define the handler to only react to the specific animation in the first place ... if anyone has any advice on the matter i would be much obliged, thanks

Edited by rudyardcatling
found "some kind of" solution
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.

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.


  • Recently Browsing   0 members

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