Jump to content

Unable to see Phaser.Graphics on WebGL


SealOfTheTime
 Share

Recommended Posts

I have initialized and used Graphics. It works perfectly on my pc, which has the worst GPU ever and doesn't support WebGL. But other players can't see lasers and other things i've drawn with Phaser.Graphics. P.s. if i draw smth with Graphics, but then generate texture for Sprite, for example, then it works. 

var lasersGraphics;

function create(){
 lasersGraphics = game.add.graphics( 0,0)
 lasersGraphics.fixedToCamera = true;
}

function render(){
 lasersGraphics.clear();
  if(player.target0 != undefined){
    lasersGraphics.lineWidth = (player.target0 == player.target1) ? 4 : 2;
    lasersGraphics.lineColor=0x7F76E2;
    lasersGraphics.moveTo(player.sprite.x-game.camera.x, player.sprite.y-game.camera.y);
    lasersGraphics.lineTo(player.target0.x-game.camera.x, player.target0.y-game.camera.y);
  }
  if(player.target1 != undefined){
    lasersGraphics.lineWidth = 2;
    lasersGraphics.lineColor=0xE27688;
    lasersGraphics.moveTo(player.sprite.x-game.camera.x, player.sprite.y-game.camera.y);
    lasersGraphics.lineTo(player.target1.x-game.camera.x, player.target1.y-game.camera.y);
  }
  lasersGraphics.lineWidth = 2+Math.sin(0.001*game.time.now);
  lasersGraphics.lineColor=0x000000;
  for(var i =0; i < enemies.length; i++){
    enemies[i].render();
    if(enemies[i].hooked && enemies[i].sprite.alive){
      lasersGraphics.moveTo(player.sprite.x-game.camera.x, player.sprite.y-game.camera.y);
      lasersGraphics.lineTo(enemies[i].sprite.x-game.camera.x, enemies[i].sprite.y-game.camera.y);
    }
  }
  lasersGraphics.updateCache();//last thing i added, thinkin that problem caused by caching Graphics object
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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