Tobi Reif Posted February 4, 2016 Share Posted February 4, 2016 In a Pixi project I have many lines like this: spriteFoo.position.x = someValue; When I delete the ".position" in all of these lines spriteFoo.x = someValue; everything still works. What's the intended use of ".position" ? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 4, 2016 Share Posted February 4, 2016 Its architectural decision. ".position" is the real stuff, while ".x" is just a shortcut property that is used by newbies. "position", "scale", "skew", "pivot", and "anchor" and some other things are Points. Some useful functions are working with Point type. Also, imagine that sprite will have "positionX", "positionY", "scaleX", "scaleY", "skewX", "skewY", "pivotX", "pivotY", "anchorX", "anchorY". It will be a disaster. In next version (v4) "transform.position" will be real stuff, while ".position" and ".x" will be properties. Transform type will differ for 2d sprites and 3d ones. Quote Link to comment Share on other sites More sharing options...
tips4design Posted February 4, 2016 Share Posted February 4, 2016 Yea, spriteFoo.x is just an alias for spriteFoo.position.x Here is the link in the Pixi.js source where those aliases are actually created: https://github.com/pixijs/pixi.js/blob/master/src/core/display/DisplayObject.js#L165 x: { get: function () { return this.position.x; }, set: function (value) { this.position.x = value; } }, Quote Link to comment Share on other sites More sharing options...
Tobi Reif Posted February 4, 2016 Author Share Posted February 4, 2016 I'll use ".position.x" and ".position.y", it could be a tiny bit faster because it's more direct than the short version. Quote Link to comment Share on other sites More sharing options...
d13 Posted February 4, 2016 Share Posted February 4, 2016 2 minutes ago, Tobi Reif said: I'll use ".position.x" and ".position.y", it could be a tiny bit faster because it's more direct than the short version. I'm pretty sure performance is exactly the same for both. Quote Link to comment Share on other sites More sharing options...
Tobi Reif Posted February 4, 2016 Author Share Posted February 4, 2016 Depends ... eg https://bugzilla.mozilla.org/show_bug.cgi?id=626021 . 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.