How to run two actions of two images simultaneously?
Posted: 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:
=====================
I wrote the following codes in the card so that the boy can be moved to right and left using two keys.
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
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:
2. The second image is a boyon 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
=====================
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