Animation Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Fuv
Experienced Solver
Experienced Solver
Posts: 52
Joined: Sun Jan 10, 2010 4:26 pm
Location: Gdansk PL

Animation

Post by Fuv » Sun May 23, 2010 9:27 am

Hello,
I am trying to make an animation from what I learnt in my previous topic:
http://forums.wxwidgets.org/viewtopic.php?t=27893

I want to move image smoothly from place to place.

I put the bitmap with image somewhere in the window. And then i want to move it, for example only in x-axis. In OnPaint() function i have code:

Code: Select all

dc.DrawBitmap(BALL_BITMAP, x, y, true);
and in function in which I want to move my bitmap:

Code: Select all

for(int i=0; i<Dist; ++i)
    {   
        ++x;
        Refresh();
        //Sleep(10); 
    }
Dist is a variable with point (X) whereinto I want to move my image.

I thought it should work, but it doesn't. The image just disappear from start position and appear in target.

I tried to use Sleep() function where I wrote it as a comment, but then firstly there is delay and no chnages - again the image appear without moving effect.

Is there any way to make the nice effect of moving the picture?

Kind Regards
Fuv

Drev
Knows some wx things
Knows some wx things
Posts: 34
Joined: Sat Mar 15, 2008 10:40 am

Post by Drev » Sun May 23, 2010 10:17 am

I suggest to place a timelastcall variable as a member of the class where to diplay the bitmap.

when you draw, you check if it's time do draw

if(elapsedtime - timelastcall > time_to_wait)

where elapsedtime is the time elapsed since the begin of the application, you can use on of these functions http://docs.wxwidgets.org/2.6/wx_timefunctions.html

and time_to_wait the delay of animation in milisec, for a 1 sec animation set_time_to_draw = 1000, and for a faster animation time_to_draw = 1000 / 40

This is just an idea, this is untested but it should works.
This is what I do when I use SDL, but there is maybe another way with WX.

you can but these variables into a derivated class of bitmap...

frank_frl
Earned some good credits
Earned some good credits
Posts: 139
Joined: Sat Feb 18, 2006 1:41 pm
Location: Germany

Re: Animation

Post by frank_frl » Sun May 23, 2010 10:43 am

Fuv wrote: and in function in which I want to move my bitmap:

Code: Select all

for(int i=0; i<Dist; ++i)
    {   
        ++x;
        Refresh();
        //Sleep(10); 
        wxGetApp().Yield(); // give your app a chance to draw !!!
    }
A Refresh() will just add an event to the event queue. Since your are in a loop here, you must give your app a chance to handle those events.

Frank
WinXp SP3, OS X10.5.5; CodeLite, Dialog::Blocks, wxWidgets 2.8.10

Debster
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sat Aug 20, 2005 6:01 pm

Post by Debster » Sun May 23, 2010 11:12 am

How about a wxTimer? Start it with the proper delay between the images. Redraw bitmap and restart the timer.

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Sun May 23, 2010 3:48 pm

"Keyboard not detected. Press F1 to continue"
-- Windows

Fuv
Experienced Solver
Experienced Solver
Posts: 52
Joined: Sun Jan 10, 2010 4:26 pm
Location: Gdansk PL

Post by Fuv » Sun May 23, 2010 6:04 pm

I tried this two ideas from the link, but I don't understand it at all. Could you give me simpler example?

The idea with Yield is working, but it looks bad. Its not clearly drawn on the frame. Frame is blinking all the time.

Kind Regards
Fuv

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Sun May 23, 2010 8:52 pm

Fuv wrote:I tried this two ideas from the link, but I don't understand it at all. Could you give me simpler example?
These examples are about as minimal as possible :/ can you be more specific as to what you don't understand?
"Keyboard not detected. Press F1 to continue"
-- Windows

Post Reply