Solved

Animation

Posted on 1999-01-19
7
318 Views
Last Modified: 2013-11-19
I would like an example of simple animation using a timer.
For example every half second a circle moves 10 pixels across the screen.
0
Comment
Question by:bradsoblesky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 

Accepted Solution

by:
cdc_sickle earned 30 total points
ID: 1184563
void __fastcall TForm1::ExampleTimer(TObject *Sender)
{
short t;
ExampleTimer->Interval = 400;
t++;

if (t==5) t=1;

if (t==1) Ball->Left += 10;
if (t==2) Ball->Left += 10;  //blah blah, and so on, is this what you wanted?
//=+ is just, where the ball is, plus 10 more

}
//---------------------------------------------------------------
0
 

Expert Comment

by:cdc_sickle
ID: 1184564
this is a very simple way of doing it, i dont know if you wanted more coplicated, also, short t, would be declared in the program or form create lines, and same with the setting the interval of the timer
0
 
LVL 1

Expert Comment

by:MCoroli
ID: 1184565
There are several examples in C++ Builder3 and in Delphi.
They are enough simple.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bradsoblesky
ID: 1184566
cdc_sickel could you please give great details.  For example lets say the ball is in a picturebox and I want to move the whole picturebox to make it look like the ball is moving.  I also have no clue where or in what file to put this in.  
Is this under the timers event calls or whatever?
0
 

Expert Comment

by:cdc_sickle
ID: 1184567
Hmm, ok, this is all timers, and are you saying an image box from a bitmap?

Ok, lets say you have your bmp in the same directory of the program your making. This file name is called Ball.bmp.
You place a timer, and a ImageBox on the form, and goto the code.
Right after the "#pragma resource "*.dfm""
Type
   short b;

b represents the Ball for the timer to work off of, as in the animation code i put above.

In the __fastcall of TForm1
put the following:

NameOfTimer->Interval = 400; //Anywhere from like 10 - 700 could do.

NameOfImageBox->Picture->LoadFromFile("Ball.bmp"); //Telling the Image box to be the Ball when the program starts

Also, have a button on the form...
In the OnClick property for that button, type:

NameOfTimer->Enabled = true; //Animation Start

Now, for the timer property's you type somthing like...



ExampleTimer->Interval = 400;
t++;

if (t==3) t=1; //This is a continuous loop, that would make the ball go right off the screen.

if (t==1) NameOfPicture->Left += 10;
if (t==2) NameOfPicture->Left += 10;  //blah blah, and so on, is this what you wanted?
//+= is just, where the ball is, plus 10 more



There are many ways of going about this, but this is a simple way that i found, you could also make another botton that has the code like

NameOfTimer->Enabled = false;
NameOfImage->Left = 70; //or what ever the picture started at.
0
 

Author Comment

by:bradsoblesky
ID: 1184568
Now thats what I'm talking about.  Thanks A Lot!!!
0
 

Expert Comment

by:cdc_sickle
ID: 1184569
He he, your welcome!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to convert MFC::CString to UTF8 wchar_t* 10 375
Grunt Copy file to another destination. 1 76
Outlook 13 80
migrating to phpbb forum from vBulletin 4.2 3 27
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question