Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Sprite Texture from Graphics Object


MrSnrub
 Share

Recommended Posts

Hi,

I am trying to create a sprite whose texture comes from a graphic object, but each time I try to do it I get the missing image (green box with a slash).  Could you point out what I'm doing wrong?  I have tried the following two ways

 

function create ()
    {
        var graphics = this.add.graphics();
        var color = 0xffff00;
        var thickness = 2;
        var alpha = 1;

        graphics.lineStyle(thickness, color, alpha);
        graphics.strokeRect(32, 32, 256, 256);

        graphics.generateTexture("test");
        graphics.destroy();

        sprite = this.add.sprite(400, 300, this.textures.get("test"));
    }

 

function create ()
    {
        var graphics = this.add.graphics();
        var color = 0xffff00;
        var thickness = 2;
        var alpha = 1;

        graphics.lineStyle(thickness, color, alpha);
        graphics.strokeRect(32, 32, 256, 256);

        var texture = graphics.generateTexture();
        graphics.destroy();

        sprite = this.add.sprite(400, 300, texture);
    }

Thank you

Link to comment
Share on other sites

  • 7 months later...
 Share

  • Recently Browsing   0 members

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