Jump to content

How Can You Destroy a Key?


FKL34TI5T5
 Share

Recommended Posts

I have a card game that I want to animate a card flip from a sprite sheet. It works fine except that I don't see that there is a way to destroy a key once it is done. This code shows the same cards over and over.

How can I destroy a key or get my animation to be tied to the passed variable in the argument?

function dealCards(c1, c2, c3, c4, c5) {
        
        let c1frameNames = game.anims.generateFrameNames('cards', {start: 1, end: 7, zeroPad: 0, prefix: c1 + '/', suffix: ''})
        gopherswild.anims.create({ key: 'c1animation', frames: c1frameNames, frameRate: 18, repeat: 0 })
        let c2frameNames = game.anims.generateFrameNames('cards', {start: 1, end: 7, zeroPad: 0, prefix: c2 + '/', suffix: ''})
        gopherswild.anims.create({ key: 'c2animation', frames: c2frameNames, frameRate: 18, repeat: 0 })
        let c3frameNames = game.anims.generateFrameNames('cards', {start: 1, end: 7, zeroPad: 0, prefix: c3 + '/', suffix: ''})
        gopherswild.anims.create({ key: 'c3animation', frames: c3frameNames, frameRate: 18, repeat: 0 })
        let c4frameNames = game.anims.generateFrameNames('cards', {start: 1, end: 7, zeroPad: 0, prefix: c4 + '/', suffix: ''})
        gopherswild.anims.create({ key: 'c4animation', frames: c4frameNames, frameRate: 18, repeat: 0 })
        let c5frameNames = game.anims.generateFrameNames('cards', {start: 1, end: 7, zeroPad: 0, prefix: c5 + '/', suffix: ''})
        gopherswild.anims.create({ key: 'c5animation', frames: c5frameNames, frameRate: 18, repeat: 0 })

        card1.anims.play('c1animation')
        card2.anims.play('c2animation')
        card3.anims.play('c3animation')
        card4.anims.play('c4animation')
        card5.anims.play('c5animation') 
}
Link to comment
Share on other sites

Answer is the remove method. 

        game.anims.remove('c1animation')
        game.anims.remove('c2animation')
        game.anims.remove('c3animation')
        game.anims.remove('c4animation')
        game.anims.remove('c5animation')

//If you need to wait for the event, then use this:

        card1.on('animationcomplete', ()=>{game.anims.remove('c1animation')}, this)
        card2.on('animationcomplete', ()=>{game.anims.remove('c2animation')}, this)
        card3.on('animationcomplete', ()=>{game.anims.remove('c3animation')}, this)
        card4.on('animationcomplete', ()=>{game.anims.remove('c4animation')}, this)
        card5.on('animationcomplete', ()=>{game.anims.remove('c5animation')}, this)

 

Edited by FKL34TI5T5
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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