Jump to content

What is the recommended way to draw primitives?


ABev
 Share

Recommended Posts

I'd like to draw some circles and lines that need to be dynamically shaped and sized (so just using textures isn't an option)

 

I've run across both Phaser.Graphics and the Phaser.BitmapData objects which seem to have a similar purpose.  Can someone explain the difference intentions for their use?  And is it possible to use BitmapData with WebGL rendering (the interface seems quite like the 2d canvas)?

 

Thanks!

Link to comment
Share on other sites

Phaser.Graphics creates the primitives using vectors in WebGL. It's fine if you only need a handful of them, but slows down really quickly if you start ramping up the numbers. BitmapData works by creating a texture and uploading it to WebGL each time you modify it, but at least it's just a single transfer. Even so, if you can avoid doing it (by using Graphics) then I would start off by trying there first.

Link to comment
Share on other sites

On the topic I found a way to draw a rectangle but i didn't find a polygon method and i went for this:

 

    drawPoly :function(poly){        var graphics = this.add.graphics(0, 0);        graphics.beginFill(0xFF3300);        graphics.lineStyle(10, 0xffd900, 1);        graphics.moveTo(poly[poly.length-1].x,poly[poly.length-1].y);        for(var i=0,len = poly.length-1; i<=len; i++){            graphics.lineTo(poly[i].x, poly[i].y);        }        graphics.endFill();        graphics.alpha = 0.4;    }

 

Should I try adding this to Phaser core and make a PR ?

 

Or is there other plans or ways for this...

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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