Mattward

Cordova Buttons do not work

Recommended Posts

Hi,

 

This works when I run it in cordova:

    game.input.onUp.add(jump, this);

 

However this doesn't:

    enPlayButton.onInputDown.muff.add(PlayFunction, this);

 

And when I change it to use the first example, like so:

    enPlayButton.input.onUp.add(PlayFunction, this);

 

It still won't work.. Does anyone know why?

 

Here is the full code if you need it: http://pastebin.com/UyPh1U9F

 

First example is on line 1728.  Second example is on line 554.

Share this post


Link to post
Share on other sites

Instead of using a button, I used a sprite which mimics the behavior of a button and now everything works well:

    this.toggleButton = this.game.add.sprite(0, 0, 'toggleButton');    this.toggleButton.frameName = 'onUp.png';    this.toggleButton.inputEnabled = true;    this.toggleButton.events.onInputDown.add(downState, this);    this.toggleButton.events.onInputUp.add(upState, this);    this.toggle = false;    function downState () {        if(this.toggle === false) {            this.toggleButton.frameName = 'onDown.png';            this.toggle = true;	    //add your callback        }        else{            this.toggleButton.frameName = 'offDown.png';            this.toggle = false;            //add your callback        }    }    function upState () {        if(this.toggle === true) {            this.toggleButton.frameName = 'offUp.png';            this.toggle = true;            //add your callback        }        else{            this.toggleButton.frameName = 'onUp.png';            this.toggle = false;	    //add your callback                   }    }

Share this post


Link to post
Share on other sites

This doesn't seem to work for me?

I used this:

            this.homeButton = this.game.add.sprite(homeButtonX, homeButtonY, 'homeButton');

            this.homeButton.inputEnabled = true;

            this.homeButton.events.onInputDown.add(HomeFunction, this);

I can't figure out why?! The sprite displays and everything runs fine but nothing happens when I click it?

Share this post


Link to post
Share on other sites

For your game you can try something more simple:

    this.toggleButton = this.game.add.sprite(0, 0, 'toggleButton');    this.toggleButton.frameName = 'onUp.png';    this.toggleButton.inputEnabled = true;    this.toggleButton.events.onInputDown.add(downState, this);    function downState () {            this.toggleButton.frameName = 'onDown.png';	    //add your callback        }

Share this post


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.

Guest
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.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.