9
Vote

Auto-flash

This is something I found handy for cases when I wanted a layer to “flash”, i.e. turn on for a few seconds and then automatically turn off. It can also be used for moving things someplace and then back again, etc. You can do this with wm_schedule by scheduling a “sleep” action between two things or something, but somehow I'd rather avoid having a bunch of things in the queue. This feels more like a “set-and-forget”.

To trigger the flash (say, in a tap action):

wm_schedule {action='tween', tween='x', from=-100, to=100, duration=4, easing=outInExpo }

You can use any other tween (instead of 'x'), and the duration is in seconds of about how long the flash is to last. Then, in the opacity of the layer that's going to flash:

100-math.abs(tweens.x)

Or if you want it flash off, use just “math.abs(tweens.x)”. Either way, you'll need to initialize (set) tweens.x in the main script somewhere.

This works because we're using the tween to “slide” the value between -100 and 100, using the outInExpo function. Thing is, the outInExpo function spends almost all of its time just about in the middle of its range, and very little time approaching and leaving it. So the value is around zero for most of those four seconds. By using math.abs() (absolute value), we get something that goes from 100 to 0, stays there a while, and comes back to 100.

Published by Mark Shoulson on 27 August 2015WatchMaker Tips & Tricks Posted

This Website and It's Resources are Powered by:
  
WatchMaker Beautiful Watches for Android Wear

No smartwatch required!! Best clock wallpaper for Android!
  
WatchMaker Live WallPaper

Introducing the Perfect Companion App for WatchMaker...
  
GearsPro (OBD 2 & Car)