Jump to content

Width and Height not initialized correctly (equal 1)


bali33
 Share

Recommended Posts

Hi guys,

 

When I create a Sprite from an Image and try afterwards to retrieve its width and height properties the console display 1 and 1. I tired to do it after the Sprite was added to the stage but the result is the same. It's very annoying because when I try to compute bounds or localBounds they return also 1 and 1 for width and height which it's not very convenient ;-)

 

Any idea why ?

 

Thank you

Link to comment
Share on other sites

Version 1.6.0

 

Code pretty simple : 

this._targetArea = PIXI.Sprite.fromImage("assets/spritesheets/lessonSelector.png");	this.addChild(this._targetArea);	console.log(" this._targetArea.width : " + this._targetArea.width + " this._targetArea.height : " + this._targetArea.height);
Link to comment
Share on other sites

Oh I guess you are right. I have just looked up the source and it seems that the width and height are never set. That would explain the weird anchor bug that I had lately.

I will take a closer look to confirm the issue. Or maybe it is?

It's weird that you get a width and height of 1 pixel tho.

edit:

Try: console.log(this._targetArea.texture.frame);

And tell me if it shows the correct values.

edit

Okay, what I can tell for now is that sprites now use pivots for rotation.

This doesn't solve your issue though.

I can only suggest to check those values:

console.log(this._targetArea.width, this._targetArea.height, this._targetArea.texture.frame.width, this._targetArea.texture.frame.height, this._targetArea.scale.x, this._targetArea.scale.y);

Link to comment
Share on other sites

If your assets are already loaded then you could construct your sprite like this :

this._targetArea = new PIXI.Sprite(PIXI.TextureCache["assets/spritesheets/lessonSelector.png"]);

Then that removes any question about the loading process interfering with with and height values being set.

For what its worth I always tend to create sprites this way and very often access their width and height values immediately afterwards, (the next line of code) in order to do things like modify pivot points and so on.

I take it that the sprite is displaying correctly?

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...