Clicking a button is activating onTap event after the button and doubleTap activates single tap... Why is that happening? How can i fix it?
statemanager.play = function(game)
{
};
var map;
var player;
var layer;
var jbut;
function onTap(pointer, doubleTap)
{
if(doubleTap)
{
}
else
{
if(player.body.velocity.x == 0)
player.body.velocity.x = 100;
else
player.body.velocity.x = player.body.velocity.x * -1;
}
}
function jump()
{
player.body.velocity.x = player.body.velocity.x * -1; //gambiarra!!!
player.body.velocity.y = -350;
}
statemanager.play.prototype = {
preload: function() {
this.load.tilemap('ht', 'maps/happytown.json', null, Phaser.Tilemap.TILED_JSON);
this.load.image('chao', 'assets/happy town/ground.png');
this.load.image('plataforma', 'assets/happy town/plat1.png');
this.load.image('bg', 'assets/happy town/bg.png');
this.load.image('jumpbut', 'assets/jump.png');
this.load.atlasJSONArray('dog', 'assets/dogsheet.png', 'assets/dogsheet.json');
},
create: function() {
this.physics.startSystem(Phaser.Physics.ARCADE);
this.stage.backgroundColor = '#000000';
bg = this.add.tileSprite(0, 0, 1600, 700, 'bg');
bg.fixedToCamera = true;
map = this.add.tilemap('ht');
map.addTilesetImage('chao');
map.addTilesetImage('plataforma');
map.setCollisionByExclusion([]);
layer = map.createLayer('camada1');
layer.resizeWorld();
this.physics.arcade.gravity.y = 500;
player = this.add.sprite(10, 120, 'dog');
player.animations.add('idle', Phaser.Animation.generateFrameNames('Idle (', 1, 10, ').png'), 5, true);
player.animations.play('idle');
this.physics.enable(player, Phaser.Physics.ARCADE);
player.body.collideWorldBounds = true;
player.body.setSize(54, 47, 0, -10);
this.camera.follow(player);
this.input.onTap.add(onTap, this);
jbut = this.add.button(750, 550, 'jumpbut', jump, this);
jbut.fixedToCamera = true;
},
update: function() {
this.physics.arcade.collide(player, layer);
}
};