1. #1
    Ext JS Premium Member
    Join Date
    Jul 2010
    Location
    UK
    Posts
    524
    Vote Rating
    29
    MrSparks has a spectacular aura about MrSparks has a spectacular aura about

      0  

    Default Ext.Draw - Get Sprite position?

    Ext.Draw - Get Sprite position?


    Is it possible to return the current x y position of a sprite?

    Also is there a "center" sprite function?

    Many Thanks
    MrSparks

  2. #2
    Ext JS Premium Member
    Join Date
    Mar 2011
    Location
    Germany
    Posts
    3
    Vote Rating
    0
    MeklenburgMa is on a distinguished road

      0  

    Default possible Solution

    possible Solution


    After some search within the source of "Ext.draw.engine.SVG", I found something quite usefull, that might help you and others having the same Issue out.

    x = sprite.el.dom.getAttribute("x");
    y = sprite.el.dom.getAttribute("y");

    or alternatively

    x = sprite.el.getAttribute("x");
    y = sprite.el.getAttribute("y");

    (sprite being an instance of Ext.draw.Sprite)


    Those calls will retrieve the current position. Tested with 4.1.1 (available for non-subscribers also)

    - edit -
    It seems that the return type of those calls is "string". I recommend using "parseInt(value, radix);", to convert the value.


    - another edit -
    another way to get the current position and other attributes of a sprite I recently "discovered":

    x = sprite.attr.x;
    y = sprite.attr.y;

    just take a look at
    console.log(sprite.attr);

Thread Participants: 1

Tags for this Thread