Jump to content

Is it possible to set a specific area to use for game.input.activePointer.isDown?


Recommended Posts

like this example


When using game.input.activePointer.isDown
Click anywhere on the screen to trigger an event

function update() {
    if (game.input.activePointer.isDown) {
         this.sprite.velocity.y += -50;


but Is it possible to set a specific area to use for game.input.activePointer.isDown?

Like the follow screen, on or two figer tought is possible??






Link to comment
Share on other sites

Hi @fatboyarming ,

You can use a rectangle to define the zones, and in the onDown event check the position of the pointer. I have done it in the create function.

This is the code (you can test it here):

function create() {

    //Add a rectangle. In this case it represents the left half of the screen (screen size is 800x600).
    var zoneLeft = new Phaser.Rectangle(0, 0, 400, 600);
    //And for the other half...
    var zoneRight = new Phaser.Rectangle(400, 0, 400, 600);
    //Add callback to onDown event
        //If activePointer position is on left rectangle ... 
        if(Phaser.Rectangle.containsPoint(zoneLeft, game.input.activePointer.position)){
            console.log('left zone clicked');
        //If activePointer position is on Right rectangle ... 
        else if (Phaser.Rectangle.containsPoint(zoneRight, game.input.activePointer.position)){
        console.log('right zone clicked');

I haven't used the multitouch so I can't tell you about that, but I thik you have to use the array input.pointers[].


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.

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