will-e

Clickable objects

Recommended Posts

How are simple clickable objects made in MightyEditor? I am trying to make a simple checkbox (group called buttonTears which has two sprites and a a text). Trying add simple onInputDown event will cause Uncaught TypeError: Cannot read property 'onInputDown' of undefined error. My code looks like this:

		this.buttonTears = mt.create("buttonTears");		this.buttonTears.inputEnabled = true;		this.buttonTears.events.onInputDown.add(function () {			console.log("button is Clicked");		}, this);

All help appreciated, thanks!

Share this post


Link to post
Share on other sites

Okay, I found a temporary workaround:

		this.buttonTears = mt.create("buttonTears");		this.buttonTears.mt.self.children[0].inputEnabled = true;		this.buttonTears.mt.self.children[0].events.onInputDown.add(function () {			console.log("button is Clicked");		}, this.self);

This makes the text item in my group to respond to events, but not the whole group. So next I need to figure out how to add the event listener to the whole group.

Share this post


Link to post
Share on other sites

You can't set input to the group itself in the phaser (imagine group more like  a single point instead of rectangle),

what you can do - is to to use setAll / setAllChildren

 

in your particular case - you can do something like this:

this.buttonTears = mt.create("buttonTears");this.buttonTears.setAllChildren("inputEnabled", true);this.buttonTears.children.forEach(function(child){	child.events.onInputDown.add(function () {		console.log("button is Clicked");	});});

p.s. object.mt.self == object

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.