Powers
-
@iTap-Development are you worried about loops pausing the game while they do HUGE exponentials?
If so, use messaging. Send a broadcast of the value and the power to a receiver. Let it do one iteration, then return the result along with an increment to the times it's been times'd.
Or similar abuse of messaging/broadcasting until you get the desired result.
-
@Deeeds yes it’s that I don’t want pause. I’m using it for the scrolling. I’m planning on making my own loop of sorts.
-
@iTap-Development Are you using the exponentials to slow the scrolling?
-
@Deeeds that’s what I was planning on. I have no idea if that’s how it works though, except for how it looks on my iPad.
-
@iTap-Development You've come to the right monkey. Well, actually, I'm a gorilla... but enough about me.
There's a multitude of cheat ways to do this that require very little work on your part. Here's one that's easy to articulate and understand, and hyperPad has the right tools to use:
This doesn't require using powers and squares and all that guff, because someone else is doing it for you.
Make a dummy object, and set it wherever you like, offscreen, probably best. Give it a mass you like, passable so it can't hit anything, and give it a gravity you like and an air resistance of your choosing. You'll have to experiment with these settings to get the right feel you want.
Whenever your user releases a fast scroll, grab the velocity of the scroll (I'm sure you''re already doing this) and apply it to the dummy object, going up (against) towards gravity.
And monitor its speed. Grab it every frame, and set your scrolling object to this same speed. When it reaches its peak, there's two actions you can use to deal with this.
Stopped Moving might fire, but Started Falling definitely will. Use a little of that fall to roll back at the end of the scroll just a tiny bit. This looks very cool.
-
@Deeeds that probably work, I just don’t like using dummy objects/physics to do this stuff. It’s cheating!
-
@iTap-Development This is exactly what Apple does. UIKitDynamics is invisibly attached physics objects for all their scrolling and visual responses, and even sorting collection views and a bunch of other cool stuff.
Little known secret: A lot of people think UIKitDynamics is based off Box2D. It's not, it's Bullet Physics without the 3rd dimension, and customised for their purposes. Or so I'm lead to believe. Similarly, SpriteKit physics is Bullet Physics with an API made to be familiar to users of Box2D.
In SceneKit, it's back to full 3D Bullet Physics.
-
-
@iTap-Development Me? Wrong?
Com'on now. Who do you think you're talking with?
Don't believe me. There's no need:
Watch the video: https://developer.apple.com/videos/play/wwdc2015/229/
And read for yourself:
https://developer.apple.com/documentation/uikit/animation_and_haptics/uikit_dynamics
-
@iTap-Development If your power is always staying the same, just multiply the two values together, then again and again until you reach your power. But if your power is changing during the project being run, yeah you’d use a loop or something. You know what else I’d like? More options than just square root. What about cubed root etc?
-
@Aidan-Oxley yeah the power is changing.
Yes! Other roots would be great! -
@Deeeds so if I scroll through my iMessages, thats a physics object doing the animation?
-
@Deeeds I checked out the links, pretty cool! I might make two versions of the scroll now!
-
@iTap-Development (late reply) Math behaviours should be efficient enough that you can do integer powers through loops without freezing as long as you don't have them too large. It'd probably depend on what device is running, but I can calculate the 64th power of numbers through a loop in under a frame on iPad Air 2.
-
@Jack8680 I have iPad Pro second gen.
Shouldn’t be a problem at all then. Thanks! -
Any suggestions for the best way to get the velocity of scrolling?
-
@iTap-Development What do you mean? You could use a Get Velocity behaviour?
-
@Aidan-Oxley I don’t think get velocity will work on objects being moved by move behaviors though, right?
-
@iTap-Development Oh, using Move behaviours. No it probably won’t. What you’d need to do then is divide the distance being moved by the time it’s being moved by. If your time is zero, then multiply by 60 instead of divide by time (dividing by zero is bad 😛).
-
@Aidan-Oxley ok I’ll try that. Yeah I won’t divide by zero!