Coordinates

  • Mdkar
    25th Apr 2015 Member 0 Permalink

    How can you get the coordinates of the pixels of an element using code (I think its something like tpt.get_property)?

    I want to get the coordinates and move a particular element ata time.  So, I would like to take the coordinates and add a number to them to move the element's pixels.  I don't know if this is possible, nor how I would store the data.  Does Lua have lists and would I have to store the x's in 1 list and y's in another?

  • boxmein
    25th Apr 2015 Former Staff 0 Permalink
    The preferred way to do it for an element is to add an update function - this function gets run once for every particle and is expected to do stuff to that particle alone. Which is also why update functions, among other things, get the current particle's coordinates, index and other details.
  • RCAProduction
    4th May 2015 Member 0 Permalink

    ELEM is your element.

     

     

    function ELEM_update(i, x, y, s, n)

     

    tpt.parts[i].vx=XVELOCITY

    tpt.parts[i].vy=YVELOCITY

     

    tpt.element_func(ELEM_update, elements.ELEMENT_PT_ELEM,1)

     

     

    What this should do is set the velocity of your element to XVELOCITY and YVELOCITY. Supposing VX is set to 1, and VY is set to 2, your element will move right 1, and down 2 each frame. I think that may be what you wanted?

    Edited once by RCAProduction. Last: 4th May 2015
  • ChargedCreeper
    4th May 2015 Member 0 Permalink

    @RCAProduction

     

    Why are you using the legacy API for the update function? This works too:

     

    elements.property(ELEM, "Update", funcUpdate)

    local function funcUpdate(i,x,y,s,nt)
         (update code here)
    end

  • RCAProduction
    4th May 2015 Member 0 Permalink

    Is there any advantage to that? I honestly do not know... Anyways, I'm used the legacy, so it's just what came out. 

  • FeynmanLogomaker
    4th May 2015 Member 0 Permalink

    I don't think the new api gives any performance changes, it's really just a matter of preference; if you learned with the old api, you might stay using it for familiarity.