bali33 Posted October 6, 2014 Share Posted October 6, 2014 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 Quote Link to comment Share on other sites More sharing options...
agamemnus Posted October 7, 2014 Share Posted October 7, 2014 Hmm. 1.6.0 or 1.6.1? Quote Link to comment Share on other sites More sharing options...
BasomtiKombucha Posted October 7, 2014 Share Posted October 7, 2014 Is there any chance you accidentally ask for scale.x instead of width?Could we see your code? Quote Link to comment Share on other sites More sharing options...
bali33 Posted October 7, 2014 Author Share Posted October 7, 2014 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); Quote Link to comment Share on other sites More sharing options...
Sebi Posted October 7, 2014 Share Posted October 7, 2014 Preload the image. By the time that you attach it to the stage, it didn't load the image yet. Quote Link to comment Share on other sites More sharing options...
bali33 Posted October 7, 2014 Author Share Posted October 7, 2014 All my applications images are pre-loaded included this one. I will double-check but I'm pretty sure it is the case. Quote Link to comment Share on other sites More sharing options...
Sebi Posted October 7, 2014 Share Posted October 7, 2014 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); Quote Link to comment Share on other sites More sharing options...
agamemnus Posted October 7, 2014 Share Posted October 7, 2014 If it's a case of pixi.js not setting the width and height if they don't exist, then all he has to do is set them before making the texture, right, or at most set the width of the sprite. More of a missing feature than a bug.... Quote Link to comment Share on other sites More sharing options...
alex_h Posted October 7, 2014 Share Posted October 7, 2014 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? Quote Link to comment Share on other sites More sharing options...
bali33 Posted October 7, 2014 Author Share Posted October 7, 2014 @alex_h, I will try that way - and yes, the sprite is displaying correctly. Thank you 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.