need a math formula

Discussion in 'iOS Programming' started by alexandergre, Dec 5, 2009.

  1. macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #1
    mybutton.location.x=158;
    mylable.alpha=0;

    mybutton is dragable in 259>x>158
    I want the mylable.alpha to grow from 0 to 1.0 as the x grows from 158 to 259;


    I came up with this:
    mylabel.alpha=((myButton.location.x)/259);

    It works
    but the alpha start from 0.613900 and not 0. becase 158/259=0.61003861
    I need another forumla. can you please help.

    mylabel.alpha=((myButton.location.x-158)/259) didnt work either.
    when x= 158; alpha is 0;
    but when x=259 alpha is 0.39
     
  2. Moderator emeritus

    SilentPanda

    Joined:
    Oct 8, 2002
    Location:
    The Bamboo Forest
    #2
    Get rid of the "/259". Then it will go from 0 - 99 at least. Then you just need to do "/100" to get values of 0-.99.
     
  3. macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #3
    mylabel.alpha=((myButton.location.x - 158)/101)
     

Share This Page