Raikoh

Tiles update issue.

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.

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.