Moving an image on a card

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Andycal
Posts: 144
Joined: Mon Apr 10, 2006 3:04 pm

Moving an image on a card

Post by Andycal » Mon Mar 10, 2008 4:54 pm

Is it possible to have an image or graphic on a card that the user can click on and move along a set path?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Mar 10, 2008 9:24 pm

Hi Any,

There are several ways to do this. The easiest way is to use the move command, e.g.

Code: Select all

move img 1 from 10,10 to 200,200 in 5 secs with messages
This moves the image over a straight line. A neat trick is

Code: Select all

move img 1 to the points of graphic "Polygon" in 10 seconds 
which makes the image follow a path as defined by the points of a (hidden?) polygon. You need to draw the polygon first and you should make one with very many points.

You might also create a mathematical function to calculate the points and store these points in a return delimited list. Then use this list instead of the points of a polygon graphic.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Andycal
Posts: 144
Joined: Mon Apr 10, 2006 3:04 pm

Post by Andycal » Mon Mar 10, 2008 9:36 pm

Can this command be used so they can actually drag the graphic along?

Andycal
Posts: 144
Joined: Mon Apr 10, 2006 3:04 pm

Post by Andycal » Mon Mar 10, 2008 10:36 pm

Right, just read some more docs and I realise I'm being a bit cryptic.

I've just noticed that this almost does what I want:

Code: Select all

on mouseDown pMouseBtnNum
    grab me
    
end mouseDown
    
However, I only want to move the graphic horizontally between points 10 and 150 (for example).

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Mar 10, 2008 11:14 pm

Hi Andy,

That's simple:

Code: Select all

on mouseDown
  put item 2 of the loc of me into myY
  repeat until the mouse is up with messages
    put the mouseH into myX
    if myX > 9 and myX < 151 then
      set the loc of me to the myX,myY
    end if
    wait 0 millisecs with messages
  end repeat
end mouseDown
Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Andycal
Posts: 144
Joined: Mon Apr 10, 2006 3:04 pm

Post by Andycal » Wed Mar 12, 2008 6:19 pm

Thanks for this Mark, I think I've got it now, just experimenting...

Post Reply