I need some help. Can some of you please test which of the following scripts runs smoother for you?

I need some help. Can some of you please test which of the following scripts runs smoother for you?

They are both merged versions of the Animation turn script. So for setup you can follow the instructions for that one, with the only change, that you don’t use the toggle script, but also the one you are testing.

Be sure to clear containers tag if you change to the other script.

Thanks in advance.

(scripts in comment 1&2)

]]>

10 Commentsto I need some help. Can some of you please test which of the following scripts runs smoother for you?

  1. Anonymous says:

    < ![CDATA[

    var e=LL.getEvent();


    var d=e.getContainer();


    var dwidth=d.getWidth();


    var dheight=d.getHeight();


    var cont=JSON.parse(d.getTag()|| “null”);



    if(e.getSource()!=”C_POSITION_CHANGED”){


    var items=d.getItems();


    var box=d.getBoundingBox();


    if(cont==null) cont=new Object(); cont.minx=box.getLeft(); cont.maxx=box.getRight();


    var minpage=Math.floor(cont.minx/dwidth);


    if(cont.setup!=true)


    {


    cont.pages=[];


    var counters=[];


    for(x=0;x


    {


    cont.pages[x]=[];


    counters[x]=0;


    }


    for(x=0;x


    {


    var i=items.getAt(x);


    var pinned=i.getProperties() .getString(“i.pinMode”);


    if(pinned==”NONE”|| pinned==”Y”)


    {


    var data=new Object(); data.posx=i.getPositionX(); data.posy=i.getPositionY();


    data.rot=i.getRotation(); if(i.getProperties().getBoolean(“i.onGrid”)) data.onGrid=true;


    else data.onGrid=false; i.getProperties().edit().setBoolean(“i.onGrid”,false).commit();


    var p=Math.floor(data.posx/dwidth)-minpage;


    cont.pages[p][counters[p]++]=i.getId();


    i.setTag(JSON.stringify(data));


    }


    }


    for(x=0;x


    {


    cont.pages[x].length=counters[x];


    }


    cont.setup=true; Android.makeNewToast(“Animation enabled”,true).show();


    }


    else


    {


    var cellw=d.getCellWidth();


    var cellh=d.getCellHeight();


    for(x=0;x


    {


    var i=items.getAt(x);


    var data=JSON.parse(i.getTag());


    if(data!=null)


    {


    i.setRotation(data.rot);


    i.setPosition(data.posx,data.posy);


    if(data.onGrid==true)


    {


    iwidth=i.getWidth(); iheight=i.getHeight(); i.getProperties().edit().setBoolean(“i.onGrid”,true).commit();


    i.setCell(Math.round(data.posx/cellw),Math.round(data.posy/cellh),Math.round((data.posx+iwidth)/cellw),Math.round(( data.posy+iheight)/cellh));


    }


    }


    }


    cont.setup=false; Android.makeNewToast(“Animation disabled”,true).show();


    }


    d.setTag(JSON.stringify(cont));


    }




    if(cont==null || !cont.setup || d.getPositionScale()!=1)return;


    var dposx=d.getPositionX();


    var dposy=d.getPositionY();


    var current=Math.floor(dposx/dwidth);


    var pagepos=current*dwidth;


    var percent=(dposx-pagepos)/dwidth;


    var maxpage=Math.ceil((cont.maxx-dwidth)/dwidth);


    var minpage=Math.floor(cont.minx/dwidth);



    if((percent>0.005 && percent<99.995) && dposx>cont.minx-dwidth)


    {


    var scrollLimit=d.getProperties() .getBoolean(“noScrollLimit”);


    if(dposx>cont.maxx-dwidth&&scrollLimit){


    d.setPosition(cont.minx-dwidth,dposy,1,false);


    }


    if(dposx


    cont.state=true;


    var items=cont.pages[(cont.state?maxpage:current)-minpage];


    if(items!=null)


    {


    for(z=0;z


    {


    var item=LL.getItemById(items[z]);


    var data=JSON.parse(item.getTag());


    item.setRotation(90*percent+data.rot);


    var c0=center(item,data.rot);


    var x=((data.posx+c0[0])%dwidth+ dwidth)%dwidth;


    var y=((data.posy+c0[1])%dheight+ dheight)%dheight;


    var sqrt=Math.sqrt(Math.pow(x,2) +Math.pow(y,2));


    var angle=((x==0&&y==0)?0:Math.acos(x/sqrt))+percent*Math.PI/2;


    var c=center(item,item.getRotation());


    item.setPosition(dposx+Math.cos(angle)*sqrt-c[0],dposy+Math.sin(angle)*sqrt-c[1]);


    }


    }


    var items=cont.pages[current+1-minpage];


    if(items!=null)


    {


    for(z=0;z


    {


    var item=LL.getItemById(items[z]);


    var data=JSON.parse(item.getTag());


    item.setRotation(90*percent-90+data.rot);


    var c0=center(item,data.rot);


    var x=((data.posx+c0[0])%dwidth+ dwidth)%dwidth;


    var y=((data.posy+c0[1])%dheight+ dheight)%dheight;


    var sqrt=Math.sqrt(Math.pow(x,2) +Math.pow(y,2));


    iwidth=item.getWidth()*item.getScaleX();


    var angle=((x==0&&y==0)?0:Math.acos(x/sqrt))+(percent-1)*Math.PI/2;


    var c=center(item,item.getRotation());


    item.setPosition(dposx+Math.cos(angle)*sqrt-c[0],dposy+Math.sin(angle)*sqrt-c[1]);


    }


    }


    }


    else


    {


    d.setPosition(dposx,dposy);


    d.setPosition(dposx


    cont.state=false;


    var items=d.getItems();


    for(i=0;i


    {


    item=items.getAt(i);


    var data=JSON.parse(item.getTag());


    item.setRotation(data.rot);


    item.setPosition(data.posx,data.posy);


    }


    }



    //r in degree


    function center(item,r)


    {


    r=r*Math.PI/180;


    var sin=Math.abs(Math.sin(r));


    var cos=Math.abs(Math.cos(r));


    var w=item.getWidth()*item.getScaleX();


    var h=item.getHeight()*item.getScaleY();


    return [(w*cos+h*sin)*0.5,(h*cos+w*sin)*0.5];


    }

    ]]>

  2. Anonymous says:

    < ![CDATA[

    var e=LL.getEvent();


    var d=e.getContainer();


    var items=d.getItems();


    var dwidth=d.getWidth();


    var dheight=d.getHeight();


    var cont=JSON.parse(d.getTag()|| “null”);



    if(e.getSource()!=”C_POSITION_CHANGED”){


    var box=d.getBoundingBox();


    if(cont==null) cont=new Object(); cont.minx=box.getLeft(); cont.maxx=box.getRight(); if(cont.setup!=true)


    {


    for(x=0;x


    {


    var i=items.getAt(x);


    var data=new Object(); data.posx=i.getPositionX(); data.posy=i.getPositionY();


    data.rot=i.getRotation(); if(i.getProperties().getBoolean(“i.onGrid”)) data.onGrid=true;


    else data.onGrid=false; i.getProperties().edit().setBoolean(“i.onGrid”,false).commit(); i.setTag(JSON.stringify(data));


    }


    cont.setup=true; Android.makeNewToast(“Animation enabled”,true).show();


    }


    else


    {


    var cellw=d.getCellWidth();


    var cellh=d.getCellHeight(); for(x=0;x


    {


    var i=items.getAt(x);


    var data=JSON.parse(i.getTag());


    i.setRotation(data.rot);


    i.setPosition(data.posx,data.posy);


    if(data!=null&& data.onGrid==true)


    {


    iwidth=i.getWidth(); iheight=i.getHeight(); i.getProperties().edit().setBoolean(“i.onGrid”,true).commit();


    i.setCell(Math.round(data.posx/cellw),Math.round(data.posy/cellh),Math.round((data.posx+iwidth)/cellw),Math.round(( data.posy+iheight)/cellh));


    }


    }


    cont.setup=false; Android.makeNewToast(“Animation disabled”,true).show();


    }


    d.setTag(JSON.stringify(cont));


    }




    if(cont==null || !cont.setup || d.getPositionScale()!=1)return;


    var dposx=d.getPositionX();


    var dposy=d.getPositionY();


    var current=Math.floor(dposx/dwidth);


    var pagepos=current*dwidth;


    var percent=(dposx-pagepos)/dwidth;


    var l=items.getLength();


    var maxpage=Math.floor((cont.maxx-dwidth)/dwidth);



    if((percent>0.005 && percent<99.995) && dposx>cont.minx-dwidth)


    {


    var scrollLimit=d.getProperties() .getBoolean(“noScrollLimit”);


    if(dposx>cont.maxx-dwidth&&scrollLimit){


    d.setPosition(cont.minx-dwidth,dposy,1,false);


    }


    if(dposx


    cont.state=true;


    for(i=0;i


    {


    item=items.getAt(i);


    var pinned=item.getProperties() .getString(“i.pinMode”);


    var data=JSON.parse(item.getTag());


    if(pinned==”NONE”|| pinned==”Y”)


    {


    var page=Math.floor(data.posx/dwidth)


    if(page==current||(cont.state && page==maxpage))


    {


    item.setRotation(90*percent+data.rot);


    var c0=center(item,data.rot);


    var x=((data.posx+c0[0])%dwidth+ dwidth)%dwidth;


    var y=((data.posy+c0[1])%dheight+ dheight)%dheight;


    var sqrt=Math.sqrt(Math.pow(x,2) +Math.pow(y,2));


    var angle=((x==0&&y==0)?0:Math.acos(x/sqrt))+percent*Math.PI/2;


    var c=center(item,item.getRotation());


    item.setPosition(dposx+Math.cos(angle)*sqrt-c[0],dposy+Math.sin(angle)*sqrt-c[1]);


    }


    if(Math.floor(data.posx/dwidth) ==current+1)


    {


    item.setRotation(90*percent-90+data.rot);


    var c0=center(item,data.rot);


    var x=((data.posx+c0[0])%dwidth+ dwidth)%dwidth;


    var y=((data.posy+c0[1])%dheight+ dheight)%dheight;


    var sqrt=Math.sqrt(Math.pow(x,2) +Math.pow(y,2));


    iwidth=item.getWidth()*item.getScaleX();


    var angle=((x==0&&y==0)?0:Math.acos(x/sqrt))+(percent-1)*Math.PI/2;


    var c=center(item,item.getRotation());


    item.setPosition(dposx+Math.cos(angle)*sqrt-c[0],dposy+Math.sin(angle)*sqrt-c[1]);


    }


    }


    }


    }


    else


    {


    d.setPosition(dposx,dposy);


    d.setPosition(dposx


    cont.state=false;


    for(i=0;i


    {


    item=items.getAt(i);


    var data=JSON.parse(item.getTag());


    item.setRotation(data.rot);


    item.setPosition(data.posx,data.posy);


    }


    }



    //r in degree


    function center(item,r)


    {


    r=r*Math.PI/180;


    var sin=Math.abs(Math.sin(r));


    var cos=Math.abs(Math.cos(r));


    var w=item.getWidth()*item.getScaleX();


    var h=item.getHeight()*item.getScaleY();


    return [(w*cos+h*sin)*0.5,(h*cos+w*sin)*0.5];


    }

    ]]>

  3. Anonymous says:

    < ![CDATA[

    With 16 items there is no visible difference (perhaps the first is better…)


    I’ll test with more

    ]]>

  4. Anonymous says:

    < ![CDATA[

    The first should especially be faster with a lot of pages… Theoretically.

    ]]>

  5. Anonymous says:

    < ![CDATA[

    With 41 items ( in 3 pages) I think the first is less laggy, but little difference.

    ]]>

  6. Anonymous says:

    < ![CDATA[

    Damn. All that mess for just a little difference… Well I probably won’t do that with the other animations.



    I was asking because on my phone I can’t see a difference at all

    ]]>

  7. Anonymous says:

    < ![CDATA[

    What is the difference exactly?

    ]]>

  8. Anonymous says:

    < ![CDATA[

    Also, my phone is a nexus 4, and it runs ok. You should wait until someone with a less powerful device could test it.

    ]]>

  9. Anonymous says:

    < ![CDATA[

    The first one is grouping by id all items to pages, so containers tag is a lot bigger. Then items tags are only parsed for items on the current active pages.



    The second script just parses every item tag and then checks on which page it is.

    ]]>

  10. Anonymous says:

    < ![CDATA[

    Hmm, so the first go directly to the items it knows it need to move, and the second go to all items and then decide to move it or not.


    I recommend to leave the first one, even if the time is the same. It’s better in code-side (in general is better to spend time making a directory with the data and then looking it, that check every time)

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *