I have a costum control with super class canvas. On my custom control a small Rectangle should move slowly a defined distance to the right.
I have a methode with following code:
[code] for i As Integer = 0 to 10
m_Distance = m_Distance + 5
When I count how many times the paint event of my custom control is called, it is only once and there is no movement of the small Rectangle - the Rectangle is just drawn at the final position. (50 pixels to the right)
Why is the Refresh event not fired within the for loop?
How can I get kind of a slow movement?
Where is that code? You shouldn’t need to invoke refresh if it’s in the Paint event. Otherwise, try me.Invalidate instead.
Refresh is a message sent to the queue… your for/next loop has a higher priority… so the message queue is not queried until you loop completes… at which time it sees 10 redundant refreshes… so it does only one.
I believe Invalidate sends a message that says… Hey when you got a millisecond… call the Paint event for me. So I don’t think that will help in this situation.
Your whole loop is faster than a Paint Event call (assuming all you are doing is drawing a rectangle)…
You may need to release time in the event loop to allow the OS to update the window or force the window to refresh after you’ve set up each frame.
I’ve done this in the past … using “APP.DOEVENTS”… but kept being told that was “evil”…
Lol… Me too! For this app I choose to go the window.refresh route, it seemed to be smooth enough. I really would like to find an awesome animation solution with Xojo.
I did mess around with using Core Animation, and while it works for the most part I didn’t notice any frame rate increase unless I enabled CALayers, at which point things got a little scewey so I gave up. I might tackle it again as it should be a great solution.
To get a slow movement you’ll need to use a timer with a suitable period to show the movement.
This is how I’d do it. Sorry it’s made with Xojo - you’ll need to change the extension to .rbp & ignore the warning when opening - should still work though.
Thank’s guys, you helped me out.
Wayne’s Timer solution is working for me.