Jump to content

How graphics.generateTexture() is supposed to work in Phaser 3 ?


EnderSpirit
 Share

Recommended Posts

Hello, I'm new to Phaser 3, I know how to create sprites from images, but how can I create a sprite from graphics ? I tried the following way and a lots of things, but I don't figure out how to do that. That's creating a sprite, but it's invisble. What I am doing wrong ?

class MainScene extends Phaser.Scene {

// ...

create () {

    this.physics.world.setBounds(this.BOUND_X, this.BOUND_Y, this.BOUND_WIDTH, this.BOUND_HEIGHT);
    this.cameras.main .setBounds(this.BOUND_X, this.BOUND_Y, this.BOUND_WIDTH, this.BOUND_HEIGHT);

    var graphics = this.add.graphics().fillStyle(0xff00ff).fillRect(1500, 1500, 400, 400);

    graphics.generateTexture('box', 400, 400);

    this.sprite = this.physics.add.sprite(200, 200, 'box').setCollideWorldBounds(true);

    // ...

}

// ...

Thanks !

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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