Car animtaion help
Author |
Message |
mafia101
|
Posted: Sat Jan 16, 2010 9:54 am Post subject: Car animtaion help |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
What is the problem you are having?
<Answer Here>
Describe what you have tried to solve this problem
<Answer Here>
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
<Answer Here>
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
trafficlight.t |
Filesize: |
2.7 KB |
Downloaded: |
88 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
ProgrammingFun
![](http://compsci.ca/v3/uploads/user_avatars/11682880074bcb590d30b0a.png)
|
Posted: Sat Jan 16, 2010 9:57 am Post subject: RE:Car animtaion help |
|
|
It would be nice if you specified what your problem is, your version of turing, and what you have tried to solve this problem
|
|
|
|
|
![](images/spacer.gif) |
TerranceN
|
Posted: Sat Jan 16, 2010 10:50 am Post subject: Re: Car animtaion help |
|
|
In order for there to be animation, you need change where the car is drawn every frame.
Here is part of a tutorial I did for another forum, it teaches basic animation.
Animation
Animation is simply the illusion that something is moving. It is created by showing many frames with small differences very fast. It can be done by using a loop, variables for the changes every frame, and redrawing the frame every loop.
For example we can make a simple animation by using a loop and a variable for the x position of a oval:
Turing: | % define variable to store x position
var x : int := 0
% start loop
loop
% increase x so oval moves right 1 pixel every frame
x + = 1
% clears the screen to draw the next frame
cls
% draws the oval using x to create animation
Draw.FillOval(x, 100, 5, 5, black)
end loop |
There are a few problems with this. First, it is going too fast. We can fix this by using the Time.Delay(millisecs : int) function. This delays however many milliseconds you enter into it. Our Code becomes:
Turing: | % define variable to store x position
var x : int := 0
% start loop
loop
% increase x so oval moves right 1 pixel every frame
x + = 1
% clears the screen to draw the next frame
cls
% draws the oval using x to create animation
Draw.FillOval(x, 100, 5, 5, black)
% delay so we can see oval moving
Time.Delay(10)
end loop |
But there is one last problem that you may have noticed. When the oval moves, it randomly flashes. This is because of the split second after we clear the screen, the oval is not there. We can fix this by using a backbuffer. This is the idea that instead of drawing to the screen, we draw to a 'fake' screen represented by memory in RAM, and just switch the two screens, to avoid seeing a blank screen. In Turing we have to use the function View.Set(flags : string) putting in text to specify the drawing options(one of them being to use a backbuffer). There are a few options but the most common are:
- graphics:width;height - This sets the width and height of the window.
- offscreenonly - This sets Turing to draw to a backbuffer.
- nobuttonbar - This sets Turing not to display the buttons at the top of your application window.
- title:App Title - This sets the title of the application.
All of these are separated by commas, so using all four would look like this:
Turing: | % sets window size, uses backbuffer, removes button bar, and sets title
View.Set("graphics:500;500,offscreenonly,nobuttonbar,title:Example") |
In order to use a backbuffer there is one more command, View.Update(), that flips the two screens, that should be called at the end of drawing each frame, giving us this:
Turing: | % sets window size, uses backbuffer, removes button bar, and sets title
View.Set("graphics:500;500,offscreenonly,nobuttonbar,title:Example")
% define variable to store x position
var x : int := 0
% start loop
loop
% increase x so oval moves right 1 pixel every frame
x + = 1
% clears the screen to draw the next frame
cls
% draws the oval using x to create animation
Draw.FillOval(x, 100, 5, 5, black)
% flips buffers
View.Update()
% delay so we can see oval moving
Time.Delay(10)
end loop |
I hope that helps.
|
|
|
|
|
![](images/spacer.gif) |
mafia101
|
Posted: Sat Jan 16, 2010 8:49 pm Post subject: Re: Car animtaion help |
|
|
mafia101 @ Sat Jan 16, 2010 9:54 am wrote: What is it you are trying to achieve?
I need help making the car look like it is driving on the road, the car is the box.
What is the problem you are having?
I don't know how to make it look animated
Describe what you have tried to solve this problem
I tried making multiple boxes but it didn't work
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
<Answer Here>
|
|
|
|
|
![](images/spacer.gif) |
|
|