How to apply timer based throb or pulse or fade-away effects to an image in IPhone or iOS? - iphone

This is a multi-part question:
How can one create an animation-block and hook it up with a timer such that the animation block runs when the image is put on display in the iPhone?
How can any one of the following three effects be applied to an image?
throb effect
pulse effect (same thing as throb as far as I can guess)
fade-away or fade-out effect

Apply the size or alpha transforms to your image within the animation block, and then create a callback function (called after the animation is complete) that calls a function that applies the opposite animated transform to your image. Then the callback for that function will start the cycle again, and so on.

Related

Check if object is all painted

I have a brown sprite, which contains a hole with triangular shape.
I've added a trail renderer (and set its order in layer to appear behind the sprite), so the user can paint the sprite's hole without painting the sprite itself.
My question is: how can it detect when the hole is all painted?
I thought about using a shader to check if there is any black pixel in the screen, but I don't know if it's possible, because the shader won't know in what percentage of the image it is.
One way would be to take a screenshot with the ScreenCapture.CaptureScreenshotAsTexture method and then loop through an array of pixel colors from Texture2D.GetPixels32. You could then check if the array contains 'black' pixels.
I would do it in a coroutine for better performance as doing it every frame may slow down your application. Also what is important when it comes to CaptureScreenshotAsTexture according to unity docs:
To get a reliable output from this method you must make sure it is called once the frame rendering has ended, and not during the rendering process. A simple way of ensuring this is to call it from a coroutine that yields on WaitForEndOfFrame. If you call this method during the rendering process you will get unpredictable and undefined results.

Flare/Flutter: How to reset the progress of an animation before starting it?

I have a Flare file with 3 animations contained within it, all in the same artboard. I understand that when switching between animations, Flare will mix the animations together by default, and that playing one animation will not reset the relevant nodes values back to what they were on frame 0 in the editor. That is the behavior I would like to achieve: when playing a new animation, I would like the previous animation to stop completely (don't mix them at all) and for the incoming animation to start at the very beginning with all its default values.
The use case is this:
Play an animation where, say, the opacity of a shape goes down to zero
Play a different animation that uses the shape from above, but in the Flare editor its opacity is 1 at the start of the animation
Desired result: the new animation resets the opacity of the shape and then begins and plays like normal
Actual result: since the previous animation changed the shape's opacity, the new animation will use the shape how it is instead of how it was created in the editor
For my question as explained on GitHub you can look at the end of the thread on this issue (has gifs): https://github.com/2d-inc/Flare-Flutter/issues/14
In the above thread, Luigi Rosso mentions "re-instancing" the artboard. Does anyone know what he means by this and how to do it? I have tried several methods of doing this such as the makeInstance methods found on classes such as FlutterActorArtboard, ActorNode and some others (there are a few variants of the makeInstance method but they are all similarly named and return a new artboard. However, I had no luck with replacing the current instance of my artboard in a FlareController implementation so far.
I have also tried to manually loop through all of the ActorNodes of the artboard and first saving their initial values and then copying the saved values to the artboard every time a new animation is played, but this seemed to break things pretty badly (the animation was unrecognizable and just didn't play correctly after that, so I must have done something wrong. Or I'm resetting the wrong values).
Any help is appreciated, thanks!
For playing a different animation on a shape and resetting its opacity, you can access the opacity of the node at runtime with:
ActorNode myNode = _artboard.getNode("nodeString");
myNode.opacity = 0.00;
As outlined here in the manual.
More simply, in the new animation, you can set a keyframe in the Rive/Flare editor for the opacity to be 1 at the start of the new animation, so that when it plays the animation from the beginning its opacity will be reset to 1.
For playing one animation, then overriding it completely when the next animation plays you can extend the FlareController and create a custom animation controller to do this in the advance method.
Here's a quick and dirty example (not best practices) to give you an idea of using advance:
https://gist.github.com/she-who-codes/85d8f0da97abfc3ecc43b1cb470e9c29
https://gist.github.com/she-who-codes/ce633204cd2d4babfe9a5b54e34ca63d

How to control a Flutter/Flare animation based on timer?

I want to accomplish the following:
Based on a variable timer (hours, minutes and seconds) three goals have to be fulfilled: Received, Preparing and Ready.
Example: when the timer is about 15 seconds, the lines and the dot have to be filled with the orange color -- just in a linear way.
So far, I have accomplished this:
Where:
The first line is made with Flutter CustomPainter
The second line is made with Flare, see:https://www.2dimensions.com/a/JohanWalhout/files/flare/fill-line/embed
Now, I'm facing the follow problems:
How can I animate the Flutter CustomPainter like the Flare animation?
or:
How can I animate the Flare animation where the animation duration is the time it takes to fill the orange color?
Please, see the complete app in the following repo: https://github.com/LiveLikeCounter/Flutter-Food-Delivery
Flare and CustomPainter are two completely different things. CustomPainter is a widget that comes with the Flutter SDK and Flare is an vector animation tool by 2Dimensions. They cannot change/manipulate each other in any way.
How can I animate the Flare animation where the animation duration is
the time it takes to fill the orange color?
If you want to stick to Flare then you can separately create the fill animation and use FlareController to play the animation as and when you wish.
Just remember the name you give it e.g In this case, it is 'home-on' and 'home-off'
Refer to this blog before you start to code/design:
https://medium.com/2dimensions/building-a-responsive-house-with-flare-flutter-31af823ba805
However, it is still recommended that you use AnimationController and some variables to get full control of your widgets instead of relying on any third party animation tool.
For the custom painter you can use a basic canvas.drawLine and make sure your shouldRepaint returns true when ever the end line position changed. The end position will be relative to the timer and what you consider a line to be full.
For the Flare animation you have to create a controller that will take in the time on every timer tick you want to animate, then set your current playback time for you artboard equal to the position you want for that time. 15second = 100% in your case so your applied time should be the full animationDuration, 7.5 you'll set it to animationDuration * 0.5, so you have to figure your formula out for that.
You can use my SwipeAdvanceController from SmartFlare then call updateSwipePosition using Fake values that will represent your "swipe". The controller will advance from 0 to 100% of the animation depending on how you swipe over the animation allowing you to create sliders, etc using Flare so it should work with this by passing in fake touch positions to emulate.

IPHONE - detecting if a pointer is inside a coordinate

I have an object that can be moved across the screen with the finger. This object is an image, a small image, like a thumbnail.
On the screen I have a background image where 10 rectangles were drawn. This rectangles are part of the background image. The background image is dumb, just a UIImageView.
I have 10 sounds I want to play every time the thumbnail passes over one of the 10 areas, represented by the 10 rectangles on the background. Each area has its own sound.
All I have is the size of the translating thumbnail and its coordinates (like origin, center, width and height). I have the origin (x and y) coordinates in realtime.
The point is: how to detect if the translating thumbnail is over one of the 10 squares considering a certain tolerance (example +- 10 pixels) and discover what area is it?
The problem: as I have the origin coordinates in realtime I can always create a loop to check if this value is inside one of the 10 rectangles, but this is CPU intensive because the loop will run for each pixel the thumbnail scrolls.
Any other ideas on how to do that?
thanks for any help.
You could poll for the coordinates at a predefined interval instead of constantly.
The idea behind this is in the main loop to set off a (say 1 second) timer. When the timer finishes it fires an event in which you can inquire the current location. Then use that value to check to see which rectangle it's in.
I would use a timer to fire a method which checks them every .2-.5 seconds:
[NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:#selector(checkPointInRects) userInfo:nil repeats:YES];
Use touchesBegan,moved,ended to cache the current touches and refer to them in the checkPointInRects method. You can use CGRectContainsPoint to determine if the point lies in any given rectangle.

How can I chain animations in iPhone-OS?

I want to do some sophisticated animations. But I only know how to animate a block of changes. Is there a way to chain animations, so that I could for example make changes A -> B -> C -> D -> E -> F (and so on), while the core-animation waits until each animation has finished and then proceeds to the next one?
In particular, I want to do this: I have an UIImageView that shows a cube.
Phase 1) Cube is flat on the floor
Phase 2) Cube rotates slightly to left, while the rotation origin is in bottom left.
Phase 3) Cube rotates slightly to right, while the rotation origin is in the bottom right.
These phases repeat 10 times, and stop at Phase 1). Also, the wiggling becomes lesser with time.
I know how to animate ONE change in a block, but how could I do such a repeating-thing with some sophisticated code in between? It's not the same thing over time. It changes, since the wiggling becomes lesser and lesser until it stops.
Assuming you're using UIView animation...
You can provide an animation 'stopped' method that gets called when an animation is actually finished (check out setAnimationDelegate). So you can have an array of animations queued up and ready to go. Set the delegate then kick off the first animation. When it ends it calls the setAnimationDidStopSelector method (making sure to check the finished flag to make sure it's really done and not just paused). You can also pass along an animation context which could be the index in your queue of animations. It can also be a data structure that contains counters so you can adjust the animation values through each cycle.
So then it's just a matter of waiting for one to be done then kicking off the next one taken off the queue.
The same method applies if you're using other types of animation. You just need to set up your data structures so it knows what to do after each one ends.
You'll need to setup an animation delegate inside of your animation blocks. See setAnimationDelegate in the UIView documentation for all the details.
In essence your delegate can be notified whenever an animation ends. Use the context parameter to determine what step in your animation is currently ending (Phase 1, Phase 2, etc)
This strategy should allow you to chain together as many animation blocks as you want.
I think the answer to your question is that you need to get more specification on what you want to do. You clearly have an idea in mind, but more specification of details will help you answer your own question.