Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 multiple loops. D:
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
florayu




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: 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
Turing:

loop
    % Move both objects

    cls
    % Draw both objects
end loop


Hope that helps.
florayu




PostPosted: 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 ?
TheGuardian001




PostPosted: 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:
code:

loop
    loop
        move object 1
        exit when condition1
    end loop
    loop
        move object 2
        exit when condition2
    end loop
end loop

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
TerranceN




PostPosted: 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
Turing:

y1 := y1 + 1
x2 := x2 - 1
Sprite.SetPosition(sprite1, x1, y1, false)
Sprite.SetPosition(sprite1, x2, y2, false)


Then to draw
Turing:

Sprite.Show(sprite1)
Sprite.Show(sprite2)
delay(10)
Sprite.Hide(sprite1)
Sprite.Hide(sprite2)


As for only moving them until they get to a specific value, look at what TheGuardian001 said.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: