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

Username:   Password: 
 RegisterRegister   
 Car animtaion help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mafia101




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



trafficlight.t
 Description:

Download
 Filename:  trafficlight.t
 Filesize:  2.7 KB
 Downloaded:  88 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
ProgrammingFun




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




PostPosted: 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.
mafia101




PostPosted: 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>
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  [ 4 Posts ]
Jump to:   


Style:  
Search: