Computer Science Canada Animating a jpeg picture on a made background? |
Author: | Thatguy [ Thu Mar 14, 2013 12:33 am ] |
Post subject: | Animating a jpeg picture on a made background? |
What is it you are trying to achieve? I have made a background using the graphics mode and I wish to animate a jpeg (its a rocket) picture across my background with out having to clear the screen What is the problem you are having? I have no clue how to move the jpeg picture without messing up my background picture,the cls (obviously) would erase my entire background which is not what I want Describe what you have tried to solve this problem tried searching simliar topics on this website but could not find something as similar to my problem Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) [syntax="turing"] <Add your code here> View.Set("graphics:max;max") drawfillbox(0,0,maxx,maxy,grey) drawfillbox(20,20,maxx-20,maxy-20,white) drawfillbox(20,20,maxx-20,maxy div 3.95,green) Draw.FillBox (20, maxy div 4, maxx - 20, maxy - 20, 99) Draw.FillBox (maxx div 10, maxy div 4, maxx div 9, maxy div 2, 232) Draw.FillOval (maxx div 9.6, maxy div 2, maxx div 25, maxy div 12, green) var Rocket:int:=Pic.FileNew("rocket.jpg") var Rx1:int:= maxx div 3 var Ry1:int:=maxy div 1.5 Pic.Draw(Rocket,Rx1,Ry1,picXor) 4.1.1 |
Author: | Tony [ Thu Mar 14, 2013 1:03 am ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
it might help to think of cls as "draw white all over the screen" instead of "erasing". You are constantly just drawing new stuff on top of the old stuff, so that requires you to re-draw all (or just a part) of the background. There is no undo. Think of it as a http://en.wikipedia.org/wiki/Flip_book animation Though you get the benefit that every frame could have transparent background. This description is very close to what Turing does by default. |
Author: | Thatguy [ Thu Mar 14, 2013 1:27 am ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
Thanks, that helps my understanding with what cls does. So how would you suggest me to change the position of the Rocket? just Redraw everything a series of times with the position of the rocket changing? If so, wouldn't the screen have to be cleared in order to redraw it? |
Author: | Insectoid [ Thu Mar 14, 2013 11:00 am ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
Yes, and yes. In fact, you should do that. |
Author: | Tony [ Thu Mar 14, 2013 12:32 pm ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
Yes, you should redraw the background. You will start finding that the screen appears to be "flashing". To understand this, imagine what happens in that flip book when each frame is assembled of multiple transparent pages -- you eyes will be catching parts of incomplete frames as well. This is where View.Update comes in -- it's a way to group a number of those parts together and then "flip" all of them to screen at the same time. Though get your animation working as is first. It's an easy change from there. |
Author: | Thatguy [ Thu Mar 14, 2013 4:02 pm ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
Alright so I've cleared the screen and redrew the background enough times to make it look like the rocket is moving. Tony, you were right about the flashing, i've looked at the turing reference and usually it says to use the View.Update command in loops. The problem is that I don't want my rocket to move in a loop so I'm unsure where to put this command, between every cls? Please suggest what I can do |
Author: | Insectoid [ Thu Mar 14, 2013 4:20 pm ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
Quote: I don't want my rocket to move in a loop
Why not? A loop actually sounds like a really good idea. |
Author: | Thatguy [ Thu Mar 14, 2013 4:27 pm ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
Well,I'm making an animation story where a rocket descends from the sky and ppl emerge from it, won't the loop just mean that the rocket descends to the ground then loops again back to the sky and never stops? I'm not sure how a counted loop would work in this situation, is there a way for it too loop once so I can use View.Update? |
Author: | Insectoid [ Thu Mar 14, 2013 4:31 pm ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
You can absolutely use a loop for this. You want the rocket to stop descending when it hits the ground, right? Well, how do you know when it hits the ground? Have you heard of 'exit when'? |
Author: | Thatguy [ Thu Mar 14, 2013 4:39 pm ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
This is when my true noobiness shows. Yes, I have heard of exit when. I tried doing exit when ((Rocket=y coordinate of ground)) and then put View.Update after that (right before end loop) but it still flashes and loops, am I using exit when properly? |
Author: | Tony [ Thu Mar 14, 2013 4:43 pm ] | ||||||||
Post subject: | RE:Animating a jpeg picture on a made background? | ||||||||
you want View.Update at a point where you are done with the current "frame". This typically is the point right before cls (assuming that cls if your first step of the next frame). The use of loops typically just makes you type a lot less code. E.g. instead of having
you can simplify this into a loop
in your case, you might split this into different segments
Once you get into video games, the ultimate goal is to have a single "game loop" or "main loop" that looks something like
where a single loop drives all of the activity. This is something to look forward to, but you can worry about it later. |
Author: | Thatguy [ Thu Mar 14, 2013 5:02 pm ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
Okay, so i've tried to do the for loop but this is the result: View.Set ("graphics:max;max") drawfillbox (0, 0, maxx, maxy, grey) drawfillbox (20, 20, maxx - 20, maxy - 20, white) drawfillbox (20, 20, maxx - 20, maxy div 3.95, green) Draw.FillBox (20, maxy div 4, maxx - 20, maxy - 20, 95) Draw.FillBox (maxx div 10, maxy div 4, maxx div 9, maxy div 2, 232) Draw.FillOval (maxx div 9.6, maxy div 2, maxx div 25, maxy div 12, green) drawfillbox (20, 100, maxx - 20, maxy div 3.95, white) Draw.FillArc (maxx div 9.6, maxy div 2, maxx div 25, maxy div 12, 0, 180, white) View.Update %Person on Left drawfilloval (maxx div 4, maxy div 2.7, 25, 25, black) %torso drawline (maxx div 4, maxy div 2.7, maxx div 4, maxy div 3.7, black) %arm drawline (maxx div 4, maxy div 2.9, maxx div 3.6, maxy div 2.7, black) %Person on Right drawfilloval (maxx div 1.5, maxy div 2.7, 25, 25, black) %torso drawline (maxx div 1.5, maxy div 2.7, maxx div 1.5, maxy div 3.7, black) %arm drawline (maxx div 1.5, maxy div 2.9, maxx div 1.6, maxy div 2.7, black) loop var Rocket : int := Pic.FileNew ("rocket.jpg") var RocketPosition:int:=maxy div 1.8 for i:0..10 Pic.Draw (Rocket, maxx div 3, RocketPosition, picXor) delay (100) RocketPosition:=RocketPosition-5 View.Update exit when i=20 end for end loop as you can see the Rocket behaves oddly and it still flashes! |
Author: | Insectoid [ Thu Mar 14, 2013 5:11 pm ] | ||
Post subject: | RE:Animating a jpeg picture on a made background? | ||
You've forgotten something. Might wanna look over the View.Update reference again. |
Author: | Thatguy [ Thu Mar 14, 2013 5:41 pm ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
oop, you're right insectoid! I forgot the 'offscreenonly' for View.Set. But I still have the same problem, Is there something I messed up? |
Author: | Insectoid [ Thu Mar 14, 2013 6:02 pm ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
For one thing, you never clear the screen. If I'm reading this right, your rocket will leave a smear on the screen, like you dragged a popsicle across a table. You also never re-draw the background. To make things easy for you, you can put all of the draw commands for the background inside a procedure, and just call that procedure when you need to draw the background. You're also calling View.Update before everything is drawn. You draw a bunch of boxes and ovals, update the screen, and then draw a a couple of people. But those people don't actually show up on the screen until you're inside the rocket loop. Inside your for loop, you're drawing something, then delaying, then updating. This means that nothing gets drawn until after the delay. Maybe you should delay after you update the screen? Here's what I recommend. Put all of your background stuff inside a procedure. You can even call it 'draw_background' if you want. Then, call that procedure from inside your for loop. This way, it will get re-drawn every time the rocket moves. Then update the screen, add a delay, and then clear the screen. The loop will re-start and draw everything again before the screen is updated, so you will never notice that the screen was cleared at all. |
Author: | Thatguy [ Fri Mar 15, 2013 1:35 am ] |
Post subject: | RE:Animating a jpeg picture on a made background? |
Thank You Insectoid and Tony for your help. Both of you just earned some bits |