An object being "moved" is not where it appears to be

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

rumplestiltskin
Posts: 219
Joined: Wed Jun 21, 2006 7:33 pm
Location: West of the Pecos
Contact:

Re: An object being "moved" is not where it appears to be

Post by rumplestiltskin » Tue Feb 13, 2018 4:37 am

Seems to provide for accurate recognition of the mouseDown. That's pleasing. Thank you!

I've attached a stack based upon my old game stack (and have commented out a bunch of irrelevant script for this particular example). Click on the four buttons to "release" them. Click on them to stop them. You'll see how the speed of the moving buttons drops dramatically as more are put into motion and speeds up as you stop them, one-by-one.

I think I'll try your code with more moving objects to see what happens there.

Funny thing: I seem to remember my stack being so much smoother when all my objects (eight or so) were moving (on Core2Duo Macs). Maybe your code will result in smother moving objects.

Thanks for all the ideas!

Regards,
Barry
[-hh] wrote:
Tue Feb 13, 2018 3:13 am
rumplestskin wrote:The move command would have been so easy.
The move command can be easy: Here is just another option to show this.

Script your card with the following, no script in the moving graphic. Start with a click on the (stopped) graphic.

Code: Select all

local gotcha=true

on moveIt
  -- if "moveIt" is in the pendingmessages then exit moveIt -- for testing
  if (the shiftkey is down and the cmdkey is down) then put true into gotcha
  if gotcha then exit moveIt
  move graphic "theGold" to (457,90),(0,90),(457,90) in 4 seconds without waiting
  send "moveIt" to me in 4 seconds
  -- put the pending messages -- for testing
end moveIt

on mouseDown
  if not gotcha and the clickloc is within the rect of grc "theGold" then
    put true into gotcha
    move graphic "theGold" to (the clickH,90) -- stops moving
    answer "Ya got me, pardner!"
  end if
end mouseDown

on mouseUp
  if gotcha and the short name of target is "theGold" then 
    put false into gotcha
    set loc of grc "theGold" to (457,90)
    send "moveIt" to me in 1 tick -- start move
  end if
end mouseUp
Attachments
Release the Hounds.livecode.zip
(1.49 KiB) Downloaded 17 times

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1812
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: An object being "moved" is not where it appears to be

Post by [-hh] » Tue Feb 13, 2018 3:58 pm

Very nice stack.

For using move we have now a different scenario. This needs a handler that uses "lock moves".

I made such a stack a while ago for an HTML5 standalone, see
http://hyperhh.de/html5/mathBeauties2-8.0.2X.html
Choose there for example "Lissajous43 with 4+3=7 balls and speed 1.

I adjusted this to your scenario, using lissajousXY figures.
The number of moving object is the sum X+Y of the last two chars.
You can set 8 levels increasing with the complexity of the figures.
They have 3 up to 17 objects ("buttons/balls") that move along these figures.
Each hit by a mouseclick disables the clicked button. If all buttons are disabled you'll get your "pardner"-dialog.

Here is the core handler of the attached stack that moves ALL objects at once in small steps.

-- t0 is the send interval (millisecs)
-- s0 is the speed = step in moving along the points of the figures
-- m0 is the number of moving objects
-- n0 is the number of lines of pts (=the points of the lissajous figure)
-- current settings are t0=160, s0=2

Code: Select all

on moveAll x,y
  lock screen; lock messages; lock moves
  if (the shiftkey is down and the cmdkey is down) then
    exxit; exit moveAll
  end if
  set vis of grc g0 to (the shiftkey is down) -- base figure
  if x=-1 then put 1000 into t00
  else put t0 into t00
  add s0 to x; if x > n0 then subtract n0 from x
  repeat with i=1 to m0
    put ("."& numToChar(64+i) &".") into g
    move btn g to line x+i*y of pts in t00 millisecs without waiting
  end repeat
  unlock screen; unlock messages; unlock moves
  send "moveAll x,y" to me in t00 millisecs
end moveAll
You still have to implement levels (and will probably have to adjust t0 and s0 for each level) and possibly implement more base figures. Have fun! And please show us your final result ...
The attached stack runs with LC 6/7/8/9.
Attachments
Release the Hounds-(hh addition).livecode.zip
(4.15 KiB) Downloaded 21 times
shiftLock happens

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”