Jump to content

Using mousedown and buttons


Phempt
 Share

Recommended Posts

Hi guys,

 

I'm coding a game that by clicking on the whole screen start the jump function for the character. I used this code:

mousedown: function(){	    if(player.onGround == true){	          player.velocity.y = -player.velocityLimit.y;                  player.mass = 1;	          player.onGround = false;	    }    }

it works, the character jumps.

 

but If I've a button, for example:

    this.logo = new game.Sprite('[email protected]');    this.logo.interactive = true;    this.logo.position.x = game.system.width / 2;    this.logo.position.y = game.system.height / 2;    this.logo.anchor.set(0.5,0.5);    this.logo.scale.set(0.9,0.9);    this.logo.addTo(game.scene.bgContainer);    this.logo.click = this.logo.tap = function(){             console.log('test');    }

I see the "test" log into the console, but my character jump due to "mousedown" function.

 

is there a way through the framework to block the mousedown interaction while a button is tapped ?

 

Thank you

 

 

EDIT:

 

I tried to add to mousedown function a "interactive" control but:

    mousedown: function(object){        if(object.interactive != true){	    if(player.onGround == true){	          player.velocity.y = -player.velocityLimit.y;              player.mass = 1;	          player.onGround = false;	    }	 }    }

without success... :(

Link to comment
Share on other sites

Instead of using scene's mousedown function, create new container for your mouse events:

var touchLayer = new game.Container();touchLayer.interactive = true;touchLayer.hitArea = new game.HitRectangle(0, 0, game.system.width, game.system.height);touchLayer.mousedown = function() {};touchLayer.addTo(this.stage);
Link to comment
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...
 Share

  • Recently Browsing   0 members

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