Jump to content

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


fatboyarming
 Share

Recommended Posts

like this example

http://jsfiddle.net/lewster32/u3p5n/

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

1.JPG.6ef93612c3ecce40a60c40b6d5de2b35.JPG

 

Thanks

 

 

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
    game.input.onDown.add(function(){
        //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');
        }
    },this);
}

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

Regards.

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