[Solved] Collision map for button

Reashu

  • Posts: 16
Hi all! I was recently notified by a friend of mine that StencylWorks was in open beta, and I figured I owed it to myself to try it out. I'm running into a couple of bumps though...

One in particular I'd like share with you, and it has to do with buttons, or really anything that reacts to the cursor. I've looked, and searched, around a bit and surprisingly didn't find anything on this topic. But I still feel that I can't be the only one who doesn't want to rely on bounding boxes to decide whether the user presses a button or not. And so we've reached the topic of this thread. How should I go about using either
a) the non-transparent pixels of the actor's current animation or
b) the collision map of the actor's current animation
to decide whether the cursor is really over a button?

I tried (regretfully) making a 1x1 actor follow the cursor and use that to detect collisions, but my "solution" has at least two flaws:
1) Inelegant. It should be very possible to "eliminate the middleman" and straight-up compare to the cursor's position.
2) Incorrect. Once a collision has been detected, the hover animation will not stop until the cursor leaves the button's bounding box. There's probably something I can do to fix this, but I'm at a loss.

My "cursor tracker" and button both have their collision areas set to "sensor" and have proper collision groups set - it doesn't seem to be a problem with the tracker leaving the collision area, but rather with something not updating when I expect it to. I've tried with a collision area much smaller than that of the button's bounding box - it only triggers when an actual collision happens, but the button will stay lit up until the cursor leaves it completely.

I've attached an image of my button (to help visualize the problem :) ) and a screen-shot of my "button" design blocks.

Is there anything I can do to make the described design work properly? Am I overlooking a very useful block (or piece of AS) which would remove the need for a cursor tracker? Should I move on to square-shaped buttons?

Thanks in advance! (But I'll still thank you afterwards, too...)

« Last Edit: June 16, 2011, 11:01:06 am by Reashu »

Alexin

  • *
  • Posts: 3132
Search for Mouse Events on Collision Shape, on StencylForge. I can make a version that uses transparent pixels, instead of relying on collision shapes.
"Find the fun"
alexin@stencyl.com

Reashu

  • Posts: 16
Thank you very much! Next time I'll try being more general with my searches in the forge.

As for the modification, I figured it was a good way to start learning Action Script, so I went ahead and did it myself. It's in the forge with the name "Mouse Events on Visible Pixels". I credited you as "Alexin" - please let me know if you want another name there.

Again, thank you!

Alexin

  • *
  • Posts: 3132
Nice.

You could probably make the alpha value, used for the test, an Attribute. It makes the behavior more flexible.
If I were you, I wouldn't make the behavior rely on a collision shape, but on the sprite's bounds itself. Or make it an option.
"Find the fun"
alexin@stencyl.com

Reashu

  • Posts: 16
Thank you for sharing your ideas. I implemented them and uploaded the new version, though unfortunately I couldn't make it update the old one.