click detection

volkerk's picture

does anybody has an idea how i could detect if a sprite is rolloverd or mouse clicked. I got many sprites animated in 3D space and need to detect if one of them was selected with the mouse cursor. i did see the private hit test patch, but i don't think it is intended to be used this way.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cwright's picture
Re: click detection

Snow Leopard's interaction patch may be able to help -- if you're on Leopard, this will be extraordinarily difficult (because you'll need to calculate the projections of the sprites in 3-space, and then do a hit test -- essentially, this is just 2 matrix multiplies plus some bounds checks, but getting the matrices to multiply, along with the vertices to multiply with, is rather difficult/impossible).

volkerk's picture
Re: click detection

actually, after playing around some more with the hit test patch (on leopard) it does exactly what i need it to do, even inside an iterator.

just a matter of connecting all sprite properties (x,y,z,width,height) to the hittest patch and it works like a charm. love it.

PreviewAttachmentSize
hitest.jpg
hitest.jpg68.86 KB

cwright's picture
Re: click detection

oh wow -- I completely forgot that hittest was so versatile (I didn't remember the Z Position, or the Rotation inputs (unused in your example))

Thanks for the reminder :)

psonice's picture
Re: click detection

The hit test patch <3

I'm using that for the control points in my spline editor. It's brilliant!

Does it still work OK in SL? And how about the interaction patches I've not played with yet - how much control does it give? One thing I have to be very careful of is overlapping objects - if two control points overlap you get a hit on both, and suddenly they're in the same position and you can't separate them. I'm using some logic that pushes one out of the way when another tries to pass over it - is that possible with interaction too?