Jump to content

Parent sprite returning width = 1, despite texture loaded


charlie_says
 Share

Recommended Posts

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
	}

}

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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