Jump to content

noobshit
 Share

Recommended Posts

Hey guys! I wanted to create "can you place building here?". Sometimes I get wrong answer.

AUiTfXd.png

I create net 10x10


    createNet(width, height)
    {
        this.net.removeChildren();
        
        for(let i = 0; i < height; i++)
        {
            for( let j = 0; j < width; j++)
            {
                this.net.create(j*16, i*16, 'net');
            }
        }
        
        this.net.forEach( o => o.anchor.set(0.5, 0.5));
        this.net.setAll('alpha', '0.5');    
    }
    

I have callback: game.input.addMoveCallback( (o) => this.updateGrid()); where i try to update color


    updateGrid()
    {
        let x = game.input.activePointer.x ;
        let y = game.input.activePointer.y;
    
        x -= (x-8) % 16;
        y -= (y-8) % 16;
        
        if ( x != this.net.x || y != this.net.y )
        {
            this.net.x = x;
            this.net.y = y;
            
            this.net.forEach(o => this.updateColor(o));
        }
    }
    
    updateColor(o)
    {
        o.frame = game.physics.arcade.overlap(o, this.obstacles ) ? 1 : 0;
    }

http://pastebin.com/2jME8vbg - here is more code, I also attached full project.

I feel right x/y or frame is update too late but I don't know how to prevent it.

buildingPlacer.zip

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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