Newbie question. Simultaneous action and facing?

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
DaveyJJ
Posts: 15
Joined: Sat Aug 25, 2007 8:38 pm
Location: Waterloo, Ontario
Contact:

Newbie question. Simultaneous action and facing?

Post by DaveyJJ » Wed May 19, 2010 1:07 am

Two quick questions.

Code: Select all

on arrowKey theKey
   // move player image
   if theKey is "up" then move image "player" relative 0,-50 in 0.5 seconds
   if theKey is "down" then move image "player" relative 0,50 in 0.5 seconds
   if theKey is "left" then move image "player" relative -50,0 in 0.5 seconds
   if theKey is "right" then move image "player" relative 50,0 in 0.5 seconds
   // move ground slower in a parallax type movement
   if theKey is "up" then move image "ground" relative 0,10 in 0.5 seconds
   if theKey is "down" then move image "ground" relative 0,-10 in 0.5 seconds
end arrowKey
How do I get the player movement, on the up and down keys, for example, and the associated ground movement to work simultaneously? Sort of like ...

Code: Select all

on arrowKey theKey
   // move player image
   if theKey is "up" then move image "player" relative 0,-50 AND move image "ground" relative 0,10 in 0.5 seconds  in 0.5 seconds
   if theKey is "down" then move image "player" relative 0,50 AND AND move image "ground" relative 0,-10 in 0.5 seconds in 0.5 seconds
   if theKey is "left" then move image "player" relative -50,0 in 0.5 seconds
   if theKey is "right" then move image "player" relative 50,0 in 0.5 seconds
end arrowKey
doesn't work. Am I missing brackets to isolate each instruction before the "in 0.5 seconds" or something?

Second question. How do I make a button or image rotate at a variable speed (rotateSpeed) to always point at (track/watch) another image?

Thank you.

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

Re: Newbie question. Simultaneous action and facing?

Post by bn » Wed May 19, 2010 10:29 am

Dave,
try this

Code: Select all

on arrowKey theKey
   if theKey is up then
      set the lockMoves to true
      move image 1 relative 0,-50 in 0.5 seconds without waiting
      move button 1 relative 0,-50 in 0.5 seconds  without waiting
      set the lockMoves to false
   end if
   if theKey is down then
      set the lockMoves to true
      move image 1 relative 0,50 in 0.5 seconds without waiting
      move button 1 relative 0,50 in 0.5 seconds without waiting
      set the lockMoves to false
   end if
end arrowKey
etc.
look up "lockMoves" and "move without waiting" in the dictionary
DaveyJJ wrote:Second question. How do I make a button or image rotate at a variable speed (rotateSpeed) to always point at (track/watch) another image?
this is a bit difficult since you can not rotate images in Rev very well, 90 degree steps are ok but if you rotate them repeatedly in smaller increcments they become distorted. What I have seen is that people make multiple images that "look" into the directions you want and then show/hide them accordingly. You would still have to calculate the angle between the two objects.
But maybe someone more into games might have a better idea.
regards
Bernd

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”