charlie_says Posted August 8, 2017 Share Posted August 8, 2017 I've got a sprite, which I'm placing some other sprites into, I'd read that others had an issue with the width returning as 1, but this was to do with the texture not being loaded... Can anyone advise where I'm going wrong? export class Lightable extends PIXI.Sprite { public icon: PIXI.Sprite; public lit: PIXI.Sprite; constructor(iconRef:string, litRef:string) { super( ); this.anchor.set(0.5,0.5); let iconTexture:PIXI.Texture = PIXI.Texture.fromImage(iconRef); this.icon = new PIXI.Sprite(iconTexture); //this.icon = PIXI.Sprite.fromImage(iconRef); this.lit = PIXI.Sprite.fromImage(litRef); this.icon.anchor.set(0.5,0.5); this.lit.anchor.set(0.5,0.5); this.addChild(this.icon); this.addChild(this.lit); console.log(iconTexture.baseTexture.hasLoaded);// true console.log(this.width, "<<<");// 1 } } Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 8, 2017 Share Posted August 8, 2017 Sprite width/height is independent from children. https://github.com/pixijs/pixi.js/blob/dev/src/core/sprites/Sprite.js#L491 I recommend to be aware how width/height for sprites and containers work because it is not about logic, its about code that does not correspond to user expectations in certain cases. There's no way to find perfect logic here. If you don't like how it works, just override it, you have my blessing. Quote Link to comment Share on other sites More sharing options...
charlie_says Posted August 8, 2017 Author Share Posted August 8, 2017 ahhh I see, so because the sprite is empty, it can only have a width/height of 1. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.