Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

How to make an onInputDown function called with an argument


ItsBobo
 Share

Recommended Posts

Hi, I'm new to phaser and so this might be a basic question. I did see: 

 but that did not work for me. 

This code works: 

create: function() {

image.events.onInputDown.addOnce(this.backToMenu, this);

}

backToMenu: function() {

//do something

}

but 

create:function() {

image.events.onInputDown.addOnce(this.backToMenu, {test: 0});

}

backToMenu: function() {

//do something with this.test

}

does not work at all. If you need more code, I will show you an example project.

Thanks!

 

Link to comment
Share on other sites

13 hours ago, rich said:

Like this:


image.events.onInputDown.addOnce(this.backToMenu, this, 0, {test: 0});

backToMenu: function(sprite, pointer, yourObjectHere) {
 // Your object ({test}) only appears after the default arguments
}

 

Sorry to bother you again, but why does it say 'undefined' when I click exit?

Capture.PNG

Link to comment
Share on other sites

25 minutes ago, rich said:

Log it out. Inside 'backToMenu' do this: console.log(arguments). Then look at the output in the dev tools and see if your object appears anywhere.

Sorry if I don't understand, Dev tools doesn't have an output tab. How do I view that? Also, would it be easier if I just attach my code with my post so you can look at it?

Thanks!

 

log.PNG

Link to comment
Share on other sites

I don't mind fielding a few questions on the forum or slack, but I don't have time to download zip files and set things up and debug it all, sorry. Maybe someone else will, but at the very least the game ought to be uploaded somewhere so we can visit a simple URL instead of having to do anything locally. Also, try posting the actual errors you get in the console. If you don't know how to use the console, spend some time on YouTube watching tutorials on it, because it's invaluable.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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