Canvas and animations

What would be the best way to draw things in a canvas and animate those things?
Lets say I need a ball rotating while you drag it around the canvas.

Using a timer and doing all the code yourself is not possible in this case because the animation would suffer from being smooth for sure.
Can this be done with some iOS animation techniques? If so, any example?

I don’t use Xojo iOS, but you could use a Thread to create a game loop, and handle the input and rendering inside the loop.

There is no threads yet in iOS.

About canvas based graphics, though, I think we got a splendid example here : https://forum.xojo.com/20609-xojo-ios-as-a-games-platform

Dragging things could be done rather smoothly with the help of declares. There was a beautiful piece of code doing that from Antonio Rinaldi in the Beta channel back in December.

And regarding view animations, I had a few of them running here: https://github.com/UBogun/Xojo-iosLib
This project is currently stalled because of the 64bit debug/simulator problem but if you should encounter problems converting the view animations to 64bit compatibility just let me know.

And for your question in general: You should find the native question to your answer in the Core Animation methods. Sam’s article in the current XDev is for OS X but can be translated to iOS almost 1:1.

There are threads on iOS. They are still cooperative threads like Xojo has always had, but they’re there.

Ooops. Sorry, since they are not in the controls I did not see them. I stand corrected. Thank you.

Christoph’s question was reason enough for me to start the lib from scratch again, and this time hopefully for 64bit too. But: I have no 64bit iOS device (or is the iPad3 Retina one?). So I am not sure if it is really working.
Would be great if some of you could check if the UIVIew block animations do run on 64bit: https://github.com/UBogun/Xojo-iosLib.

Thanks a lot!

Well, it does work on my iPhone 6 but there are differences

  • In the iOS emulator, when clicking on the ‘Animate’ button the number is 4 and the square apple logo animates and rotates.
  • On the iPhone 6 the number is 8 and the square apple logo disappears outside the view and occasionally comes back.
    But I think this due the coordinates you used. :slight_smile:

So … it works fine.

Thanks for the efforts ! Highly appreciated.

Oh great! Thanks a lot! Yes, the animation properties are not optimized – I doubt anyone would want such a GUI :slight_smile:
The number was for debugging purposes. It’s the integer size in Bytes. Seems to work :wink:
When I find time, I will add the spring animations and old style animations too – they are not recommended but you can use them for a certain number of repetitions instead of the endless repeat option on the block animations.
Was a pleasure, Christoph!

I do not think the iPad 3 is 64 bit. If memory serves, 64 bit started with iPad Mini 3 and iPad Air.

But you can use if Target64 to test within your code.

Yes, that’s what I thought to remember too. Let’s hope there will be a 64bit Simulator access soon.

Oh, and Christoph: And then there’s the Motioneffects too where you can define a more complex motion, linke a ball being thrown and bouncing … Stay tuned!

http://developer.xojo.com/threading

Spring animations are included, but no Extension convenience methods for them yet.

Not to argue with you, but the human brain processes smooth transitions at 30 frames per second (depending on the brain). If you set the timer to a very fast rate, like 1 millisecond, that is 33 times faster than your brain can process.

However, I could be over simplifying it…

I would even dare to say a 1 ms delay animation would be no animation at all to human eyes. But why do you say? Is there such a delay (by error) in the project?

[quote=175503:@Meade Lewis]Not to argue with you, but the human brain processes smooth transitions at 30 frames per second (depending on the brain). If you set the timer to a very fast rate, like 1 millisecond, that is 33 times faster than your brain can process.

However, I could be over simplifying it…[/quote]

Oh boy … don’t get me started about the 30fps and 60fps debacle. There is a H U G E and let me write this again:
MONSTROUS MASSSIVE HUGE DIFFERENCE BETWEEN 30fps and 60fps. For my eyes 30fps is absolutely not smooth at all - its jerky all the way.

I guess you never played a 30fps and 60fps first person shooter and did see a difference? Nuff said…
Check this out:
http://boallen.com/fps-compare.html

[quote=175532:@Christoph De Vocht]Oh boy … don’t get me started about the 30fps and 60fps debacle. There is a H U G E and let me write this again:
MONSTROUS MASSSIVE HUGE DIFFERENCE BETWEEN 30fps and 60fps. For my eyes 30fps is absolutely not smooth at all - its jerky all the way.

I guess you never played a 30fps and 60fps first person shooter and did see a difference? Nuff said…
Check this out:
http://boallen.com/fps-compare.html[/quote]

But refreshing every millisecond would be 1000 frames per second…

Once again, maybe I am over simplifying it.

[quote=175606:@Meade Lewis]But refreshing every millisecond would be 1000 frames per second…

Once again, maybe I am over simplifying it.[/quote]
Not quite, on the iPhone, the refresh rate of the screen is limited to 60 Hz (60 fps) so any timer period below 16 ms is a waste of resources.

Still, you are maxing out the capabilities of the device, not the software.

I think a refresh would work well in this case, but hey, I could be wrong.