Tobi Reif

"sprite.position.x =" vs "sprite.x ="

Recommended Posts

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.

 

Share this post


Link to post
Share on other sites

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;
        }
    },

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.