There's a set of articles on doug about collision detecting, you might try
there as a first step.

Personally, I'd use the intersect() function instead of sprite.intersects().
This compares 2 rects and returns the rect of the shared space. So, stepping
through and using intersect((sprite x).rect, (sprite y).rect), you can check
to see if the returned rect is not rect(0,0,0,0). If so, store the sprite
and the returned rect, then do a second loop on the new list, to see which
sprite has the bigger area of intersection, and snap to that one. This will
be less accurate for non-rectangular shapes, but still a more precise way of
determining which target the user is aiming for.

> Two things:
> 
> 1) The "intersects" means that the whole sprite rectangle will be checked,
> so if you want to limit it just to the center you might want to see if,
> say, the loch/v of the sprite, or maybe the mouseloc interesects some
> particular sprite
> 
> 2) Step through it with a debugger.  Because you say it always goes to the
> lower right, I'm guessing that maybe it does snap correctly to the right
> one, EXCEPT that you never leave the loop, so it might continue on and
> eventually qualify for the lower right - presuming that's the direction
> you're going.  For instance, put a "return" statement after you set the loc
> (in the if statement) to kick you out after the first one that qualifies -
> see how that affects the performance.  But this is a good example of where
> to use the debugger so you can see what's happening.  Put a breakpoint
> (click the mouse on the 'if' statement and then press ctrl-9) on the if
> statement and run it, and see what happens when you get there.
> 
> - Tab
> 
> 
> At 08:56 AM 11/22/02, mike m wrote:
>> hello, i am making a jigsaw game (i am a newbie), i have made a grid for
>> the jigsaw pieces to snap onto, this works, but the pieces seem to snap to
>> whichever grid piece there bottom right corner is in and not the center of
>> the piece, i have checked the registration point and that is in the center
>> of the piece. i am baffled!
>> this is the code i am using to make the pieces snap to the grid pieces
>> 
>> on snapper
>> 
>> repeat with x = 17 to 32
>> repeat with y = 1 to 16
>> 
>> if sprite x intersects sprite y then
>> sprite(x).loc = sprite(y).loc
>> 
>> end if
>> end repeat
>> end repeat
>> end snapper
>> 
>> thanks in advnace :)
>> Mike

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to