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

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