Jump to content

Mouse click when outside of game world


Andy1988
 Share

Recommended Posts

Hi everyone,

I'm kind of a newbie in phaser world and I have a question. I'm trying to build TD(Tower Defense) game and I have towers that I can drag over the Map. As soon as I place tower in place, the counter starts before the next tower available. But for some reason when I hover my mouse over the outside of the game world, it triggers a mouse click and counter start before I want it to.

 

 

here is code im working with. I know is very ugly...

 

 

var game = new Phaser.Game(1280, 800, Phaser.AUTO, '', { preload: preload, create: create, update: update });

//Variables

//playerGroup
//enemyGroup
//bulletGroup
//enemyRespawnTimer
//bulletFireRate

var count = 0;
var isThere = 0;

function preload() {
    game.load.tilemap('map', 'map/map.json', null, Phaser.Tilemap.TILED_JSON);
    game.load.image('tiles', 'map/terrain.png');
    
    game.load.image('player','pics/player.png');
    game.load.image('enemy','pics/enemy/enemy.png');
    game.load.image('bullet', 'pics/bullets/bullet1.png');
}

function create() {
    game.physics.startSystem(Phaser.Physics.ARCADE);
    
    map = game.add.tilemap('map');
    map.addTilesetImage('terrain', 'tiles');
    
    back = map.createLayer('Background').resizeWorld();
    road = map.createLayer('Road');
    end = map.createLayer('endOfRoad');
    menu = map.createLayer('towerMenu');
    
    //player = game.add.sprite(400,400,'player');
    //player.scale.setTo(0.4);
    
    
    //player.input.enableDrag();
    //player.input.enableSnap(game.input.x,game.input.y,false,true);
    
    
    player2 = game.add.group(game.world, 'player',false,true, Phaser.Physics.ARCADE);
    player2.createMultiple(10,'player');
    
    
    var deadPlayer2 = player2.getFirstDead();
    deadPlayer2.reset(1170,20);
    
    
    player2.forEach(function(item){
        item.scale.setTo(0.4);
        item.inputEnabled = true;
        item.input.enableDrag();
        item.input.enableSnap(32,32,true,true);
    });

    var key = game.input.onUp.add(clickFunction, this);
    
    
}

function update() {
    
    
    if(isThere == 1){
        count++;
        console.log(count);
        if(count >= 100 && player2.countLiving() <= 9){
            isThere = 0;
            count = 0;
            var deadPlayer2 = player2.getFirstDead();
            deadPlayer2.reset(1170,20);
            
            
        } 
    } 
    
}

function clickFunction(pointer){
    //console.log(pointer.pageX, pointer.pageY);
    //player2.input.enableSnap(64,64,true,true);
    
    isThere = 1;
    
//    
//    player2.inputEnabled = true;
//    player2.input.enableSnap(64,64,true,true);
    
    
}
 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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