Android variables become inexorably linked?
<p>Ok this one is just bizarre - I needed two Rects for a Healthbar (border and color filling)</p>

<p>When I calculated the first rectangle (filling) I assigned that value to my bar rectangle - but at runtime when the filling rectangle is modified the bar is also - only by manually setting the parameters of the BarRectangle was I able to keep its shape-- how is this even possible?</p>

<p>Can variables become linked forever through simple assignment-</p>

<p>Here is the entirety of the code:</p>

<pre><code>  public class HealthBar {

public int MaxValue;
int CurrentValue;
public int TargetValue;

int margin = 10;
Rect Rectangle;
private  Rect BarRectangle;
int screenWidth;

boolean IsPlayer1;

 Paint paint = new Paint(); 

 int Green;
 int Yellow;
 int Red;

 int opacity = 196;

public HealthBar(boolean isPlayer1, DeviceProperties device, int maxvalue) {

    paint.setARGB(196, 0, 255, 0);
    paint.setStyle(Paint.Style.FILL);

Green = Color.argb(opacity, 0, 255, 128);
Yellow = Color.argb(opacity, 255, 255, 128);
Red = Color.argb(opacity, 255, 0, 128);


MaxValue = maxvalue;
CurrentValue = MaxValue;
TargetValue = MaxValue;


    IsPlayer1 = isPlayer1;

    screenWidth = device.Screen.width();

    if(IsPlayer1) {



        Rectangle = new Rect(
                             margin,                    //x
                             device.Screen.height() - 14, //y
                             margin + MaxValue,           //width
                             device.Screen.height() - 2  //height
                             );



    } else {



        Rectangle = new Rect(
                             device.Screen.width() - margin - MaxValue,                     //x
                             device.Screen.height() - 14, //y
                             device.Screen.width() - margin,          //width
                             device.Screen.height() - 2  //height
                             );




    }


//Assign Bar Rectangle to Rectangle
    BarRectangle = Rectangle;
}


public void Damage(int amount)
{
    TargetValue = CurrentValue - amount;
}

public void Update() 
{

    if (CurrentValue &gt; TargetValue)
    {
        CurrentValue -= 1;

        if (IsPlayer1) 
            Rectangle.right = margin + CurrentValue;
        else
            Rectangle.left = screenWidth - margin - CurrentValue;
    }

    if (TargetValue &lt;= MaxValue * 0.33) {
        paint.setColor(Red);
    } else if (TargetValue &lt;= MaxValue * 0.66) {
        paint.setColor(Yellow);
    } else {
        paint.setColor(Green);
    }


}


public void Draw(ResourceManager rm, Canvas c, Paint p) 
{



    c.drawRect(Rectangle, paint);
   c.drawBitmap(rm.getBitmap("healthbar"), null, BarRectangle, p);

}


    }//End HealthBar
</code></pre>

<p>The way I "fixed" it was by clunkily assigning the BarRectangle seperate:</p>

<pre><code>    Rectangle = new Rect(
                             margin,                    //x
                             device.Screen.height() - 14, //y
                             margin + MaxValue,           //width
                             device.Screen.height() - 2  //height
                             );


        BarRectangle = new Rect(
                 margin,                    //x
                 device.Screen.height() - 14, //y
                 margin + MaxValue,           //width
                 device.Screen.height() - 2  //height
                 );
</code></pre>

<p>Can anyone explain to me how assigning a variable in the COnstructor somehow makes it update it's value whenever the other variable is updated?</p>

<p>Now that I've got a reproducable issue - I think this has happened before when it came to assigning character positions, I was using a custom class to hold the values (Vector2) and whenever one got updated the other would too.</p>
