How to run two actions of two images simultaneously?

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
alex298
Posts: 101
Joined: Mon May 01, 2006 1:17 pm

How to run two actions of two images simultaneously?

Post by alex298 » Tue Apr 29, 2008 9:43 am

Hi,

I am learning to write a very simple game. I have problem in running two "actions" of two different images simultaneously.

1. The first image is a ball
===================
The img "ball" will be bouncing in a room. I use the following codes to move the ball:

Button "Move" has the following code:
on mouseUp
if the label of me is "Move" then
set the label of me to "Stop"
MoveTheBall
else if the label of me is "Stop" then
set the label of me to "Move"
exit mouseup
end if
end mouseup

On MoveTheBall
Repeat forever
-- some codes here
if the label of button "Move" is "Move" then exit MoveTheBall

move img "Ball" relative tLeftRight , tDownUp

-- some codes here

if intersect (img "ball", other images) then
-- do something here
end if

-- some codes here
End Repeat
End MoveTheBall
2. The second image is a boy
=====================
I wrote the following codes in the card so that the boy can be moved to right and left using two keys.
on KeyDown
put the KeysDown into myKeys
if myKeys is 65460 then
move img "Boy" from the loc of img "Boy" to item 1 of loc of img "Boy" - 5, item 2 of loc of img "Boy"
else if myKeys is 65462 then
move img "Boy" from the loc of img "Boy" to item 1 of loc of img "Boy" + 5, item 2 of loc of img "Boy"
end if
end KeyDown

Here's my problem:

1. When the keys hold down to move the image "boy" left and right, the img "ball" will be moving very very slowly. It seems that the MoveTheBall handler is interrupted by the KeyDown handler. How can I solve this problem.

2. This is very strange that when the arrow keys are pressed, the img "ball" will be stopped moving at once. How can I solve this problem?

Thanks and best regards
Alex
Nice to meet all of you.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Tue Apr 29, 2008 12:48 pm

I suggest to not use move, but to set the loc of your images instead. Move is known to cause stutter, sudden stops, and similar problems, especially when multiple moves are querried. Move is only usefull for moving a single object once.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Post Reply