Computer Science Canada multiple loops. D: |
Author: | florayu [ Tue Nov 16, 2010 4:51 pm ] |
Post subject: | multiple loops. D: |
What is it you are trying to achieve? So, for my gr 10 programming class, we're supposed to create an animation with 2 sprites. both moving. What is the problem you are having? I looped the first sprite so it goes in a continuous and repeated motion . Im trying to get my 2nd sprite to do a different motion at the same time, but i realized that the sprite only runs after my first loop ends. Does anyone know if you can run two loops at the same time, and how to do it? |
Author: | TerranceN [ Tue Nov 16, 2010 5:08 pm ] | ||
Post subject: | RE:multiple loops. D: | ||
Instead of running two loops at the same time, have one loop where you move both objects and draw both objects. That way every time the loop goes around, both objects will move and get drawn. Something like
Hope that helps. |
Author: | florayu [ Tue Nov 16, 2010 5:36 pm ] |
Post subject: | Re: multiple loops. D: |
my code looks like this : loop counter := counter + 1 piplupRight := Pic.FileNew ("piplup_right.bmp") piplupRight := Pic.Scale (piplupRight, 40, 50) piplupRight := Sprite.New (piplupRight) piplupLeft := Pic.FileNew ("piplup_left.bmp") piplupLeft := Pic.Scale (piplupLeft, 40, 50) piplupLeft := Sprite.New (piplupLeft) loop Sprite.SetPosition (piplupRight, w, x, false) w := w + 1 Sprite.Show (piplupRight) delay (7) Sprite.Hide (piplupRight) exit when w = 230 end loop loop Sprite.SetPosition (piplupRight, w, x, false) x := x - 1 Sprite.Show (piplupRight) delay (7) Sprite.Hide (piplupRight) exit when x <= 360 end loop so its a loop within in a loop. if the other object moves and different times, how will that work ? |
Author: | TheGuardian001 [ Tue Nov 16, 2010 5:54 pm ] | ||
Post subject: | Re: multiple loops. D: | ||
Please use [ code] tags in the future, they make it easier to read. What you have right now is something like this:
Instead of having two loops inside, you can replace them with one big loop. And instead of exit whens, you can use an if statement. [code] loop loop if condition1 then move object 1 end if if condition2 then move object 2 end if end loop end loop |
Author: | TerranceN [ Tue Nov 16, 2010 6:06 pm ] | ||||
Post subject: | RE:multiple loops. D: | ||||
You will need two coordinates and sprites, one coordinate for each location you want to draw and a sprite to draw there. Lets call them (x1, y1) and (x2, y2) and sprite1 and sprite2. Then you can change the coordinates to move the objects, something like
Then to draw
As for only moving them until they get to a specific value, look at what TheGuardian001 said. |