I just wanted to know if there is any possibility to differentiate between two sprites when they collide with a third one. For example if there are three sprites moving freely, I just want to work when two of them collide, meaning that if it collides with the other one, nothing happens. Thanks!
I expect not. Why? App Inventor is single threaded and processes instruction asynchronously. (essentially one at a time). AI is probably incapable of determining three simultaneous collisions.
If it could be determined, the way to do it is to use the Logic blocks and If statements . Examples showing how to do determine if several conditions exist simultaneously are described Chapter 18. Programming Your App to Make Decisions .
If it is possible to resolve this, you would have to write code something like If one is colliding AND If two is colliding AND If three is colliding … in pseudo code. In reality, it is doubtful all three will collide simultaneously (though they might collide very close together).
Maybe I am wrong and my logic does not apply to the situation you are trying to trap. What have you tried Jesus? Someone else might have some ideas if you could show what you are trying with an example.
Regards,
Steve
Hi @Jesusnd12
Could you clarify your question a bit?
Let’s assume you have three ImageSprites: IS1, IS2, and IS3:
- Are you concerned that if all three are touching you don’t want to do anything?
- Do you only want to do something if just IS1 and IS2 are touching, but no other combination (including all 3 touching)?
- Counter to #2, do you want any pair of touching sprites to count (IS1-IS2, IS2-IS3, IS1-IS3), just not all three touching?
Now if we add a fourth ImageSprite to the mix, IS4, how does that change things? Is IS1-IS2 plus IS3-IS4 touching a valid combination? Do you want things to fire once (because there exists at least 1 pair) or twice (because there are 2 pairs) if so?
Thank you so much for your fast replies! @ewpatton, I had three sprites, one of them had to remain unactive, while the other two should react when they touch each other. However, as their movement was random, that unactive sprite could touch the other two at any given moment. I did what @SteveJG suggests and it works, turns out that I can differentiate them with an if, and establishing a relation between the coordinates of each sprite. Thank you so much!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.