Jump to content

How to access a button's callback function.

Recommended Posts

So I'm currently trying to implement controller support in my menu. The way I'm doing this right now is by pushing all the buttons into an array and when the player presses up or down on the dpad, they traverse through the array. 


But here's the issue. What do I use to access the callback parameter of the button? 


Essentially what I want to do is when the player reaches the button he wants to press in the array, I want to run the callback function. I know phaser does the automatically if you clicked the button. But what if I want to do it manually?


if (controller.peressed.A_Button){


Link to post
Share on other sites

I'm not sure I understand your question. You don't want to use Phaser's method for attaching a callback to a button but want to use your own? You could do what Phaser does and save the callback and the callbackContext in your array as well, more or less like you've got in your code block there. Does that not work?

Link to post
Share on other sites

@drhayes I'm sorry if I phrased the question badly. Let me clarify. 

I want to use phasers call back function. When I click the button I want the function to run. 

BUT I ALSO want to run the function whenever I want (For example when the user presses A on the controller). 

Now I know I can put all the callback functions in an array (and this is what I'm currently doing). But I feel this is bad code. Because if I were to rearrange buttons, I would have to rearrange the callback functions in the code in the same order as the buttons.


I was just wondering if there was a way to access a button object's callback function. Such as playButton.callbackFunction()//runs play function. 


Where does phaser save the callback functions? Is it within the object itself or somewhere else?

Link to post
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...