Jump to content

Timer to enable input


Recommended Posts


I'm a little new to phaser and at the moment I'm having difficulties getting a button to have a cooldown. More or less, you click it and it executes its purpose and disables itself, however I'm trying to get the input to be enabled after a timer and this is where it's falling apart for me.

When I check, it's telling me "Uncaught ReferenceError: abilitiesButton is not defined" for line 651, which relates to the "abilitiesButton.inputEnabled = true;" as listed below.


        this.abilitiesPanel = this.game.add.image(1565, 10, this.game.cache.getBitmapData('abilitiesPanel'));
        var abilitiesButtons = this.abilitiesPanel.addChild(this.game.add.group());

        var abilitiesButtonsData = [
            {icon: 'homebutton', name: 'Chill Out', cost: 10, purchaseHandler: function(abilitiesButton, player) {
                player.Paranoia = 0;
                this.playerParanoiaText.text = 'Paranoia: ' + this.player.Paranoia;

        var abilitiesButton;
        abilitiesButtonsData.forEach(function(abilitiesButtonData, index) {
            abilitiesButton = state.game.add.button((100 * index), 0, state.game.cache.getBitmapData('abilitiesButton'));
            abilitiesButton.icon = abilitiesButton.addChild(state.game.add.image(0, 0, abilitiesButtonData.icon));
            abilitiesButton.details = abilitiesButtonData;
            abilitiesButton.costText = abilitiesButton.addChild(state.game.add.text(10, 10, 'Cost: ' + abilitiesButtonData.cost, {font: '14px Arial Black'}));
            abilitiesButton.events.onInputDown.add(state.onAbilitiesButtonClick, state);


    onAbilitiesButtonClick: function(abilitiesButton) {
        abilitiesButton.details.purchaseHandler.call(this, abilitiesButton, this.player);
        abilitiesButton.inputEnabled = false;
        var reduceParanoiaCooldownTimer = this.game.time.events.add(1000, this.resetAbility, this);

    resetAbility: function() {
        abilitiesButton.inputEnabled = true;


Does anyone have an idea as to what I'm doing wrong to get it to properly enable input on the pressed button after X amount of time?



Link to comment
Share on other sites

There's no reference to `abilitiesButton` at that point. You can pass it through the timer event handler:

onAbilitiesButtonClick: function(abilitiesButton) {
  // …
  var reduceParanoiaCooldownTimer = this.game.time.events.add(1000, this.resetAbility, this, abilitiesButton);

resetAbility: function(button) {
  button.inputEnabled = true;


Link to comment
Share on other sites


  • Recently Browsing   0 members

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