Watchmaker Wiki

The ultimate watch maker for Android Wear!

User Tools

Site Tools


tips:tapcolor

This is an old revision of the document!


Changing Color Through Tap Action

A feature that's becoming more and more common, especially with paid watches that can't be edited, is the ability to change the color of an item or items on your watch face via tap action. This tutorial will explain the most efficient method for doing this. We'll be using arrays, so you're going to need (at least) version 3.4 of WatchMaker to pull this off.

Examples

Main Script

 Var_clrnum=1
 var_color1={'0000ff','00ff00','ff0000','00ffff','ff00ff','ffff00','ffffff'}
 function setclr()
    if var_clrnum==7 then
       var_clrnum=1
    else
       var_clrnum=var_clrnum+1
    end
 end

Tint Field of Object

 var_color1[var_clrnum]
 

Tap Action

 Script: setclr()

Explanation

We start in the main script by initializing our variables. we do this to avoid having a variable set to NULL. The two variables we care about are “var_clrnum,” which is color selection, and “var_color1” which is the color itself. If you were wanting to have themes, where each theme has multiple colors that go together, you'd simply add a var_color2, var_color3, etc. in the same manner. Everything else would stay the same, and you'd use the same, single, var_clrnum, to set the color on everything.

Let's take a closer look at that “Var_color1.” This is called an array (or table). What we've done here is set 7 separate values to the same variable, each being a color in hexadecimal format. These seven values are comma-separated, and since they're strings, each must have a string identifier. In this case, we used apostrophes. In an array, we determine which value we want like this: var_color1[1], var_color1[2], and so on. So, all we need to do to change the color is change the number in the brackets. That's where var_clrnum comes in.

In the script, we set up a function that acts as a toggle. Each time we call the function, which we'll do via tap action, we increase the value of var_clrnum by one. When we reach the maximum (the number of entries in our array) value of 7, we simply set it back to 1. That way, var_clrnum is never a number that does not represent a value in var_color1.

All we have to do now is set the tint field of our object(s) to: var_color1[var_clrnum]

…and set the desired tap action to call the function. All the tap action does is cycle var_clrnum through it's 1-7 loop like we discussed earlier. Simple. Effective.

Add or remove colors by simply adding or removing colors in the var_color1 array, and changing the function to ensure that the maximum number matches the number of colors.

tips/tapcolor.1427723990.txt.gz · Last modified: 2015/03/30 15:59 by jt3