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

Scaling children


flogvit
 Share

Recommended Posts

I'm trying to add some sprites to other sprites. So something like this:

let width:number = 100;
let height:number = 100;
let size:number = 1;

// Pixel is a png with 1x1 size
// Create the placeholder
let background:Phaser.Sprite = this.game.add.sprite(0,0, 'pixel');
background.height = height;
background.width = width;
background.tint = 0xAAAAAA;

// Create a line
let sprite:Phaser.Sprite = this.game.add.sprite(0, 0, 'pixel');
background.addChild(sprite);
sprite.scale.setTo(1,1);
sprite.height = size/background.scale.y;
sprite.tint = 0x0;
sprite.width = width/background.scale.x;

So, is there a reason why I have to divide by the parent sprites scales when I use .height and .width? I understand that the parent/children calculation will take all into account, so in this case the sprite.scale.x will be 1 and when size is calculated it will be 100, and sprite.scale.y will be 0.01 and when calculated it will be 1 (so basically a line here).

Wouldn't it be better that I set it to x=100,y=1 and those function calculate the scale correctly? If I make children of children it would be very hard to manually calculate the size from scale.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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