Can't animate moon's rings!
Author |
Message |
Grapefruit
|
Posted: Sat Jan 05, 2013 8:28 pm Post subject: Can't animate moon's rings! |
|
|
What is it you are trying to achieve?
I'm trying to get the moon's rings to move in and out. I'm trying to use either a loop, or a if statement, but preferably a loop. However, this scene is in a bigger loop, with View.Update, so is a loop possible?
What is the problem you are having?
I don't understand how to do it. If there are any examples, or if you could edit the code, it would really be helpful. Just please link any examples here so I can check and better understand how to do this.
Describe what you have tried to solve this problem
I've tried to loop, but I don't know when to exit. Now I'm trying to do an if statement.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
var moon1:int:=40
drawfilloval(280,470,30,30,68)
drawoval(280,470,moon1,moon1,68)
drawoval(280,470,moon1,moon1,54) %background color is 54, so im trying to erase the old circle.
if moon1>=40
then moon1:=45
end if
<Answer Here>
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
<Answer Here> |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Sat Jan 05, 2013 8:36 pm Post subject: RE:Can\'t animate moon\'s rings! |
|
|
You already have a loop in the animation, right? Just pretend there's nothing else in that loop and code it the way you usually would. Just make sure there's still only one View.Update, one cls and one delay. |
|
|
|
|
|
Grapefruit
|
Posted: Sat Jan 05, 2013 8:42 pm Post subject: Re: Can't animate moon's rings! |
|
|
%moon with 2 rings that move in and out
drawfilloval(280,470,30,30,68)
drawoval(280,470,moon1,moon1,68)
%drawoval(280,470,moon1,moon1,54)
if moon1=40
then moon1:=45
end if
moon1:=moon1+1
if moon1=50
then moon1:=40
end if
moon1:=moon1-1
So now im here. Im not sure what I could do to change it so it actually works... |
|
|
|
|
|
Insectoid
|
Posted: Sat Jan 05, 2013 8:46 pm Post subject: RE:Can\'t animate moon\'s rings! |
|
|
moon1 will never change. Whatever moon1 starts as, you're adding 1, and then subtracting 1. So it always stays the same. |
|
|
|
|
|
Grapefruit
|
Posted: Sat Jan 05, 2013 9:01 pm Post subject: Re: Can't animate moon's rings! |
|
|
Ohhh okay.
I'm trying to get the rings to move continuously. How would I achieve that? |
|
|
|
|
|
Insectoid
|
Posted: Sat Jan 05, 2013 9:10 pm Post subject: RE:Can\'t animate moon\'s rings! |
|
|
I'm not sure what you mean by 'in and out'. If you want them to switch direction after reaching a certain point, then you need an extra variable to keep track of the direction it's moving in. |
|
|
|
|
|
Grapefruit
|
Posted: Sat Jan 05, 2013 9:12 pm Post subject: Re: Can't animate moon's rings! |
|
|
could you explain that a bit more?
Yeah, I want it to change direction once moon1=45 and start moving until moon1=40 then move out again. |
|
|
|
|
|
Insectoid
|
Posted: Sat Jan 05, 2013 9:35 pm Post subject: RE:Can\'t animate moon\'s rings! |
|
|
The following example will use a direction variable to move a circle back& forth across the screen:
code: |
var direction: int := 1
var speed : int := 5
var x : int := 10
loop
Draw.FillOval (x, 100, 10, 10, red)
if direction = 1 then %check which direction the ball is going
x := x+speed %move the ball in that direction
else if direction = -1 then
x := x-speed
end if
if x < 10 then %oops, we hit the wall!
direction := 1 %change to the other direction
else if x > 630 then %oops, we hit the other wall!
direction := -1 %change direction again!
end if
end loop
|
Do you think you can apply this concept to your problem? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Grapefruit
|
Posted: Sun Jan 06, 2013 2:38 pm Post subject: Re: Can't animate moon's rings! |
|
|
Thank you so much! I used the concept and it worked~ |
|
|
|
|
|
|
|