It looks like you're new here. If you want to get involved, click one of these buttons!
I am currently working on creating my own buttons.
Originally, my idea was to add 1 to some variable, each time my button is pressed. However, I have a problem. Every time I press the button it increases the variable a number of times as my "single" click is to considered by the iPad to be somewhat lengthy.
I tried to find the millis function to monitor the time between two consequent touches, but I couldn't.
What is the usual workaround this problem?
Thank you,
Alex
Comments
maybe: add 1 only when touch.state== BEGAN
For some strange reason it doesn't work, this is my piece of code:
The "onCircle" function just makes sure I pressed the button and not something else.
CurrentTouch's state will stay "BEGAN" until it is moved or ended. So basically, if you touch and leave your finger there without moving, it will be counted as began for as many frames as your finger stays there. Instead, use the touched function, which is only called when there is a touch EVENT, instead of remaining constant.
Thank you, this helped a lot.
You're welcome, any time!
Apparently, I still fail to understand how the function works"
This is my "main" tab
This is my class
It still reacts several times, when I press once.
The problem is your still passing CurrentTouch to your oval button class, what you should be doing is adding the touched function to you main tab like this...
Thank for the help so far:)
Now I've run into a different kind of problem. How does Codea handle multitouch? I mean my program is run step by step, there are no parallel processes, how can Codea, then, deal with a number of touches simultaneously?
My problem is this:
I have a space ship
When the left button is pressed - activate the left engine
When the right one is pressed - activate the right one
I can handle this problem with a single touch, but I fail to understand how to deal with it if I want to implement multitouch? Say, when I press both buttons, I want both engines to run.
@alexNaumov That's where the touch ID is used. Run this code and touch the left or right side of the screen.
@alexNaumov You should use the touched function thats automaticlly called whenever the screen is touched instead of using CurrentTouch in your draw loop. Since CurrentTouch always is the last touch even if the screen isnt being touched that can cause big problems.
Putt the function in your main tab and then pass the touch to your buttons. It only runs when the screen is touched so it saves some power.