I wrote a script to use as a launch animation that scales an item up and then down again (kinda like a bounce).

I wrote a script to use as a launch animation that scales an item up and then down again (kinda like a bounce). It works pretty good, but for some reason it makes LL use a ton of battery. Can anyone explain to me why or even suggest a better way to do it?

function fillOptions(options, defaults){

options = options || {};

for(var p in defaults){

if(typeof options[p] === “undefined”)

options[p] = defaults[p]

}

return options;

}

function setAndClearTimeout(func, timeout){

var id = setTimeout(function(){

clearTimeout(id);

func();

}, timeout);

}

function animScale(it, newScale, duration, options){

options = fillOptions(options, {animType: null, clearBindings: true});

var varName = “scaleAnim”;

var form = “animate(‘$”+varName+”‘, “+duration;

if(options.animType!==null)

form += ‘, “‘+options.animType+'”‘;

form += ‘)’;

var prop = it.getProperties();

var onGrid = prop.getBoolean(“i.onGrid”);

if(onGrid){

it.setBinding(“s.iconScale”, form, true)

}else{

it.setBinding(“t.sx”, form, true);

it.setBinding(“t.sy“, form, true)

}

LL.setVariableFloat(varName, newScale);

setAndClearTimeout(function after(){

if(options.preciseFinish){

if(onGrid){

prop.edit().setFloat(“s.iconScale”, newScale).commit()

}else{

it.setScale(newScale, newScale);

}

}

if(options.clearBindings){

if(onGrid){

it.unsetBinding(“s.iconScale”)

}else{

it.unsetBinding(“t.sx”);

it.unsetBinding(“t.sy“);

}

}

if(options.after){

options.after()

}

}, duration)

}

function bounce(it, duration, scaleIncrease, options){

options = fillOptions(options, {after: null});

var itProp = it.getProperties()

, itScale;

if(itProp.getBoolean(“i.onGrid”)){

itScale = itProp.getFloat(“s.iconScale”)

}else{

itScale = it.getScaleX()

}

animScale(it, itScale+scaleIncrease, duration/2, {animType:”de”, clearBindings:false, after: function(){

animScale(it, itScale, duration/2, {animType:”ac”, after: options.after, preciseFinish: true});

}});

}

var e = getEvent();

var it = e.getItem();

bounce(it, 100, 0.25, {after: function(){

setAndClearTimeout(function(){

if(it.getIntent().getAction() == “android.intent.action.MAIN”){

getActiveScreen().runAction(EventHandler.RUN_SCRIPT, it, getScriptByName(“Scaling Animation”).getId());

}else{

it.launch()

}

},0)

}});

http://t.sy
]]>

3 Commentsto I wrote a script to use as a launch animation that scales an item up and then down again (kinda like a bounce).

  1. Anonymous says:

    < ![CDATA[

    i just use bindings on the items that I want to “bounce” … e.g.


    Scale X set to


    1 + $bounce*0.2*(animate(‘$ll_second’,500,”li”)%1)


    where $bounce is a binary variable to toggle whether i want bouncing to occur


    not sure if it uses a ton of battery, since i have nothing to compare it with …

    ]]>

  2. Anonymous says:

    < ![CDATA[

    But if you apply this on multiple items they will all bounce right? I only want the animation to occur when I tap an item.



    As comparison you could just disable the binding and check LL battery usage right?

    ]]>

  3. Anonymous says:

    < ![CDATA[

    yes, i have multiple items bouncing simultaneously. i don’t see a noticeable battery usage difference when the binding is off …

    ]]>

Leave a Reply

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