Jump to content

Tiles update issue.


Raikoh
 Share

Recommended Posts

I have a tilemap with all tiles set to alpha = 0, when my character come close to a tile it becomes visible. The issue is that the tiles seem to update only when my camera moves. Like when the camera needs to scroll to follow the character all is ok, but when the camera doesn't have to move if my character is close to the edge the tiles stay invisible until the camera move.

 

    this is in my create function:

 

            this.map = this.game.add.tilemap('tilemap');
            this.map.addTilesetImage('pixel', 'pixel');           
            this.layer1 = this.map.createLayer('layer1');
            this.layer1.resizeWorld();
            this.map.setCollision(1);         
 
            this.sprite = this.add.sprite(50, 50, 'sheep');            
            this.game.physics.enable(this.sprite);            
            this.game.camera.follow(this.sprite);  
 
            var tiles = this.layer1.getTiles(0, 0, 2961, 2961); //I set all the tiles to alpha(0);
            for (var i = 0; i < tiles.length; i++) {
                tiles.alpha = 0;
 
     and this in the update:    
 
            var tiles = this.layer1.getTiles(this.sprite.body.x - 20 , this.sprite.body.y - 20 , 80, 80);//I get all the tiles close to me and make them visible  
            for (var i = 0; i < tiles.length; i++) {
                tiles.alpha = 1;
            }  
 
So this would work fine if the camera were always moving when the character does, but i think phaser don't look at the tiles when the camera isn't moving (since it doesn't need to in normal use of tiles).
I tried to see if i could force the update of tiles at every loop but didn't find anything, could use some help, thx.
ps: i use typescript.
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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