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
me.Refresh
next[/code]
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?
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)…
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.