Rect Contains button sticks

I’m using some rect contains touch controls as shown here:

speed = 0;
if (accelButton.Contains(touchPos)){
speed = 1;
}

But when I take my finger off the rect area the speed continues to = 1. If I set speed to 0 at the begin of the update there is no difference. What is the best way to reset this value back to 0 once the user removes their finger from the device?
thanks.

use an “else” after the if and assign the speed to 0 there :smile:

hope it helps!

Thank you for your suggestion, but when I use the “else” statement it only returns the speed value back to 0 when I press down on another rect area.

Is there anyway that I can have the value reset back to 0 when the touch is removed from the rect area? Here is my current example:

if (accelButton.Contains(touchPos)){
speed = 1;
}
else{
speed = 0;
}

Well, assign it to zero if the user dont touch other rects. if he touch other rects then set it to 1.

I was able to reset the value back to 0 when no buttons are pressed by adding a touchCount command. This creates a problem when 2 or more buttons are pressed however because the count is not zero.

var count = iPhoneInput.touchCount;
if (count = 0){
speed = 0;
}

Do I have to start assigning IDs to each finger to get the speed to reset while another button is being pressed at the same time? Thanks.

Hello!
in Theory you should not be able to have problems as when the buttons are pressed, the counter is going to increase (I hope you understand me)

The issue is that all buttons return a value of “true” if only one button is still pressed. For example, if you press button (1) and then button (2), then lift from button (1), button (1) is still “true” because the total count still does not equal 0. I need a way to constantly update which buttons are being touched each frame and reset the ones that are no longer being touched.

an Idea has just come to my head :smile:

create an array of booleans, each slot on the array represents a button, with that way you’ll be able to know which ones are pressed :smile:
hope it helps! :smile:

if (==)

Yogan, could you extend your explaination a bit? What (if anything) am I checking to see is equal? Thanks.

use == instead = on if