Posted: Wed Nov 02, 2011 9:26 pm Post subject: Re: Animating Background picture, while having a picture in front (and staying there)
/facepalm
You could have kept your code in the procedures. Just remove the loops from the procedures. That would ensure that it runs the first and second procedure without getting caught in another loop.
You could control it with a delay, if you wanted.
Turing:
procedure leftEye
% Code end leftEye
procedure rightEye
% Code end rightEye
% Main Program loop
leftEye
delay(1000)
rightEye
delay(1000) endloop
Those delay's might not exactly be what you want. But those procedures should make it easier ....
Sponsor Sponsor
TigerFallOut
Posted: Wed Nov 02, 2011 10:18 pm Post subject: RE:Animating Background picture, while having a picture in front (and staying there)
err, now one left eye appears, it disappears, then right eye appears, and it disappears....
And i think i have too much code in the program... it runs quite slowly....
Dreadnought
Posted: Thu Nov 03, 2011 12:38 pm Post subject: Re: Animating Background picture, while having a picture in front (and staying there)
So you want to have two eyes blinking at the same time on this domo thing. So I suggest have one procedure to draw both eyes when they are closed, another to draw them when they are opened, and one to draw the body.
Sorta like this
Turing:
proc drawBody
%code to draw the body of the domo thing end drawBody
proc drawEyesOpen
% code to draw the eyes when they are open end drawEyesOpen
proc drawEyesClosed
% code to draw the eyes when they are closed end drawEyexClosed
loop
% Eyes are open
drawBody
drawEyesOpen
Time.Delay(1000)
% Eyes are closed
drawBody
drawEyesClosed
Time.Delay(300)
endloop
You can add in View.Update to make it prettier.
Hope this helps.
Zren
Posted: Thu Nov 03, 2011 2:27 pm Post subject: RE:Animating Background picture, while having a picture in front (and staying there)
Again, I'll touch on the more advanced thinking than the 'just making it work' method.
As your eventual goal is to have some blinking eyes on top a background that's being animated every frame, you'll want to stop bottlenecking your program by throwing tons of delays in there. This doesn't mean take your current code and delete all your delays, but to rethink your program's flow.
When drawing, you should be thinking along the lines of "What is the state of the left eye?" and "What is the state of the background?"
There are two states for your background. backgroundState = start with green or start with purple. As well as two states for your eyes eyeState = open or closed. An example of the program flow would be (render = draw):
code:
proc update
updateEyes
updateBackground
end
loop
update
renderFrame
end loop
But now we're updating every frame! Say we have a program that only has objects that change state periodically, like if we were just controlling the eyes (and not the background), how would we use the same program flow, but reduce redundant rendering? We'll we'd check if we've changed states during the update, which would then trigger a redraw.
A good way to do this might be to use a flag variable in the scope that all the update functions can access.
code:
var changed :boolean := false
proc updateEyes()
...
changed := true
end updateEyes
loop
update
if changed then
renderFrame
changed:= false
end if
end loop
In both cases, we'll still want to limit the framerate with a delay so our simple program doesn't max out our CPU. Eg: fpsDelay = 1000 / desiredFPS
code:
loop
if update then
renderFrame
end if
delay(fpsDelay)
end loop
A simple way to update your eyes would be to store the last time your eye changed states, then check if it's been 3 seconds since they've opened or half a second since they've closed. The updateBackground would be easier since it's cycling every frame and you don't need to keep track of anything extra.
TigerFallOut
Posted: Thu Nov 03, 2011 6:44 pm Post subject: RE:Animating Background picture, while having a picture in front (and staying there)
I didnt really get that......
but right now, my picture is working.... so, I'll try to figure that out later, cuz this thing is due tomorrow.
Thanks for everybody's help, i learned quite a lot (although a lot of it was kinda advanced for me since i just started using turing in september with barely any previous programming knowledge)