Jump to content

Create an empty Phaser.Image of a given size


gcardozo
 Share

Recommended Posts

Hi,

when I create an empty image, I always get a 32x32 pixels image.

//As you can see, I'm not passing any 'key'
this.img = this.game.add.image(x, y);

Then, even after adding a rectangle to my Phaser.Image, its size is still 32x32.

this.rect = new Phaser.Graphics(game);
this.rect.beginFill(color, alpha);
this.rect.drawRect(0, 0, 200, 100);
this.rect.endFill();

this.img.addChild(this.rect);

And if I manually set the image width and height properties, it would scale the image children.

So, how can I create an empty Phaser.Image of a specific size?

Edit:

I'm not sure this is the right way of doing it, but I guess I could give this image a texture with the size I need.

 

Link to comment
Share on other sites

When you omit key the object gets the default texture, which is 32 × 32 transparent.

this.img = this.game.add.image(x, y);
this.img.texture === Phaser.Cache.DEFAULT; //-> true

You can make a transparent image of the size you want in your image editor and use that.

Also this may work:

this.img = this.game.add.image(x, y, this.make.renderTexture(200, 100));

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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