A
Ari-Antti
Guest
I face this kind of problem very often with multiple object instances.. and i am sure there is better way handling this than what i use. I just don't know what it is and can not find answer in documents..
I give an simple example where this could happen, and how i solve this.
We have 10 instances of object Ball, 9 blue Balls and 1 red Ball.
All 10 balls are flying around aimlessly bouncing and they can overlap each other.
User should click red ball, doesn't matter if he hits same time blue ball or not as long he hits red one.
How i would solve this:
I would make Tap event for object Ball, and there look if Balls sprite color is blue or red.
if it would be red.. that would be easy.. case closed.
If its blue ball however.. i would need to use global variable, lets call it Timeout.
I need to set it to 5 for example if ball is blue.
Then i would go in Step event and make code:
If(Timeout>0)
{
Timeout--;
if(Timeout==0)
{
//here i can safely say that user did not hit Red ball, just one or more blue balls.
}
}
So problem is that if there would be situation where user hits red ball, but same time hits one or more blue balls..
My way of programming does work.. but thats just ugly!
Need to make global variable just for this, need to recognize this situation in multiple events..
There must be better way?
Can i somehow peak in Tap event that is there going to be more Tap events pending?
In that case i could just ignore blue ball, except if its last Tap handle.. then i can safely say that "nope, didnt hit red ball"
I give an simple example where this could happen, and how i solve this.
We have 10 instances of object Ball, 9 blue Balls and 1 red Ball.
All 10 balls are flying around aimlessly bouncing and they can overlap each other.
User should click red ball, doesn't matter if he hits same time blue ball or not as long he hits red one.
How i would solve this:
I would make Tap event for object Ball, and there look if Balls sprite color is blue or red.
if it would be red.. that would be easy.. case closed.
If its blue ball however.. i would need to use global variable, lets call it Timeout.
I need to set it to 5 for example if ball is blue.
Then i would go in Step event and make code:
If(Timeout>0)
{
Timeout--;
if(Timeout==0)
{
//here i can safely say that user did not hit Red ball, just one or more blue balls.
}
}
So problem is that if there would be situation where user hits red ball, but same time hits one or more blue balls..
My way of programming does work.. but thats just ugly!
Need to make global variable just for this, need to recognize this situation in multiple events..
There must be better way?
Can i somehow peak in Tap event that is there going to be more Tap events pending?
In that case i could just ignore blue ball, except if its last Tap handle.. then i can safely say that "nope, didnt hit red ball"