May not be possible but ...

87 views
Skip to first unread message

Barry Evans

unread,
Feb 10, 2016, 11:13:51 AM2/10/16
to MIT App Inventor Forum
Hi folks,

I am finding App Inventor to be an excellent tool and am having a lot of fun with it making apps. One issue I'm having difficulty overcoming is image sprites and collision detection. I have added gif images into the sprites to change their appearance but the hit detection range is still the 30x30 box that the sprite fills rather than the shape of the image I have uploaded. Is there any process to get around this is the collision detection restricted to the boundaries of the sprite itself?

Thanks for any help

Barry

Scott Ferguson

unread,
Feb 10, 2016, 3:24:14 PM2/10/16
to MIT App Inventor Forum
"is the collision detection restricted to the boundaries of the sprite itself"
Yes.
And if you rotate a long thin horizontal ImageSprite 90degrees so it's vertical, it's bounding box is still the original horizontal shape, unfortunately.
If you want to make the area that is detected as a collision more accurate, you might try  one of these tricks:

Create a second invisible sprite that is centered on the target ImageSprite but smaller and closer to the average size of the image.
Keep it centered by having it track the x,y of the target sprite inside a clock Timer event block.
Use that smaller ImageSprite to detect the collisions.

-or-

Do a calculation when there is a collision to determine how far the colliding ImageSprite's edge is from the target ImageSprite and either consider it a collision or ignore it until the colliding ImageSprite reaches a minimum distance from the target Imagesprite's center.

Ball sprites work better in this regard as their circumferences are where the collision is detected, not a square bounding box so their collisions are much more accurate.
---

Barry Evans

unread,
Feb 11, 2016, 3:26:02 AM2/11/16
to MIT App Inventor Forum
Thank you very much Scott, that's an excellent reply and very very useful. I've seen a fair bit of your work since I started learning to use this utility and you have some seriously remarkable insight. i really appreciate you sharing a bit of wisdom with me there that will really help me in developing my apps. Slow progress as every new task is another stumbling block just now, but good folks like yourself make a big difference!

Thank you again,

Barry
Reply all
Reply to author
Forward
0 new messages