Snap Objects to Each Other

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Location: New York
Contact:

Snap Objects to Each Other

Post by endernafi » Sat Jan 25, 2014 2:45 pm

Hi folks,

This is not a question, rather an answer; well kinda 8)
Peter asked in the list for a solution to snap objects which are moved and/or resized.
Since, I don't use dropbox or any other file sharing service;
I found suitable to post the stack here.

Also, some of you may find my code useful.

It's not without drawbacks, actually there are many.
But it's a quick attempt, please feel free to change it in anyway or improve and use it.
snapButton.zip
(3.51 KiB) Downloaded 331 times
Best,

~ Ender Nafi
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

Peter Bogdanoff
Posts: 3
Joined: Mon Aug 26, 2013 6:49 pm

Re: Snap Objects to Each Other

Post by Peter Bogdanoff » Sat Jan 25, 2014 9:58 pm

Ender,

This is great. Thanks!!!!

I made modifications to the script (stack attached) for my particular application (I'm working with rows of buttons):

1. buttonActive snaps to buttonListener--buttonListener never moves
2. Once snapping has occurred, buttonListener still doesn't move
3. I've removed the snapping to tops and bottoms--I don't want that for what I'm doing

Now, can there be multiple listening buttons? I'm thinking that while the active button is being dragged, it periodically checks a list of possible listening buttons to see if any one of them has met the close enough criteria--then designates that one as the listener.

Peter
Attachments
snapButton2.zip
(4.34 KiB) Downloaded 323 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Snap Objects to Each Other

Post by bn » Sat Jan 25, 2014 10:53 pm

Hi Ender,

this is a beautiful stack, thank you. Lots of good stuff in it.

Kind regards
Bernd

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Location: New York
Contact:

Re: Snap Objects to Each Other

Post by endernafi » Sun Jan 26, 2014 9:08 am

Bernd,
That's very kind of you, thanks.
I know it's a bulky code but that's me learning day by day.

Peter et al.,

I added functionality for multiple listeners.
It wasn't an easy task, at least for me; but it's fun to deal with it 8)

There are still many issues, feel free to dive in to pinpoint and hopefully fix them.
Check the comments for those which I've noticed.
Btw, I've changed the stack's name to a cooler one ;-)

This is for general use:
magnetObjects.zip
(7.36 KiB) Downloaded 344 times
And this is for Peter, adjusted for that 3 items above:
snapButton_multipleListeners_forPeter.zip
(7.05 KiB) Downloaded 300 times
This is just a stripped out and a bit altered version of magnetObjects.

Peter,
I wouldn't use that code as it is.
Since it's an alteration of the above stack, it has more issues.
Try creating a dedicated script for your needs using my script's concept.
That is if you find it useful 8)


Hope it helps some of you...

Best,

~ Ender Nafi
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Snap Objects to Each Other

Post by jmburnod » Sun Jan 26, 2014 10:21 pm

Hi Ender,
Simple, elegant... Epicurian

Congratulation

kind regards

Jean-Marc
https://alternatic.ch

endernafi
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 296
Joined: Wed May 02, 2012 12:23 pm
Location: New York
Contact:

Re: Snap Objects to Each Other

Post by endernafi » Mon Jan 27, 2014 5:23 am

Epicurean?
That made my day, thank you 8)

The problem is, Jean-Marc,
that I never was able to get things done in 100%.
Even in my school years, my grades were 85 ~ 95 {that's B+ in US system, I guess}.
No less, no more.

This stack isn't different in these manners.
Making something absolutely perfect requires just too much effort and IQ ;-)


~ Ender
~... together, we're smarter ...~
__________________________________________

macOS Sierra • LiveCode 7 & xCode 8

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Snap Objects to Each Other

Post by jmburnod » Thu Jan 30, 2014 6:54 pm

Hi Ender,
that I never was able to get things done in 100%.
It is often difficult to decide when the application is finished
I suspect it is also accept that it is not perfect yet
You may see an example about wide checkbox in this thread
http://forums.runrev.com/phpBB2/viewtop ... 49&t=14346

Best regards
Jean-Marc
https://alternatic.ch

Post Reply

Return to “Games”