iPhone animation: how do I animate the filling up of an area? - iphone

Consider a circle. Now consider a radius of the circle, drawn from the center of the circle towards the right. Now imagine that the radius is rotating about the center of the circle, sweeping out an area as it rotates. My problem is: I want to use iPhone's animation techniques to fill up the swept out area with a different color from the background area of the circle, as the radius rotates from 0 degrees to any chosen number of degrees about the circle.
I've looked through the Core Animation API, KeyFrame Animations, etc. but I am not able to find out how to do this. Any hints will be most welcome.
Thanks,
Sandeep

Check out CAShapeLayer. It lets you animate between two Core Graphics paths, which can be as complex as you want. In this case, you might want to animate between a path which defines a thin filled wedge and a filled wedge that covers a larger angle of the circle. You may need to use a CAKeyframeAnimation to make sure that it is animated in the sweeping motion you desire, and in the direction you want.

Related

How to fill mapbox polygon with fadeout color?

I have a triangle polygon filled with color and low opacity. That was no problem so far.
What I'm trying to achieve looks like this (without points and lines). It is basically triangle polygon with fill color but opacity smoothly lowering from one of the triangle apexes.
Is there any way to achieve this with mapbox? Thanks!
There is no easy, built in way to do this with Mapbox GL JS.
The best way I can think of is to create a Marker (an HTML object anchored at a specific lat/lng) to draw the shape. You will have to do some maths to translate the coordinates of the triangle's vertices into screen coordinates. You will also have to update the calculations if the viewport zooms or rotates.

How can I make the SCNCamera that i instantiated zoom into only nodes that i want in SceneKit

Pretend i have 3 nodes in total. One of the nodes is a large SCNShere and i put the camera inside this sphere and make the sphere double sided with a textured image. I then put in two smaller spheres next to each other in the center inside this sphere. I also allowCameraControl. I want to be able to zoom into these two smaller spheres without zooming into the larger sphere and messing up the detail on that sphere.
You can't put limits on the camera that's automatically created with allowCameraControl. You'll have to do your own camera management, using your own gesture recognizers.
Another solution would be to rethink your approach to the background image. Instead of using a sky sphere for the background (which is what it sounds like you're doing), use a skybox, or cube map. You can supply a cube map through the scene's background property. The SCNMaterial documentation explains the options for supply a cube map.
Hmm, I wonder what would happen if you use the large sphere's textured image/material as the scene's background, instead of putting it on an enclosing sphere?
I like the idea of using an image as the background but there are two problems. One is i looked on the web for ways to make an image the background and none of them work. Two I want the background to have depth so in order to go on that idea I need to find a way to zoom into the background and have the image pan in the opposite direction that I drag.

ios game make a mask layer effect

I need a 'mask' layer that covers the whole screen, with the center part (a circle) to be transparent. Then I can move the mask layer around using touch. User are only able to see the transparent part in the middle.
I don't think a png file can help because the file need to be very large to cover the whole screen.
So is it possible to do it by coding?
i found this online, but don't know much about openGL. http://www.cocos2d-iphone.org/forum/topic/7921.
it would be great if i can use a CCMaskLayer and input with the radius. i can handle the touch event by my self.
the attached png file is expected result, the center part is transparent. i need this to cover my screen, and only show the middle part. the red part is covered.
I write a CCMaskLayer to do the exactly same thing.
https://github.com/smilingpoplar/CCMaskLayer
You may solve this task with cropped circle texture in two ways:
1) Draw sprite with circle texture in screen center and draw another 4 sprites around (on top, bottom, left and right sides) with small red texture but scaled to cover all screen.
2) (more elegant but harder to implement) Make your mask layer fullscreen but adjust texture coordinates. In details:
set wrap mode to GL_CLAMP_TO_EDGE to your circle texture
adjust texture coordinates of your layer vertices (to do this you need to subclass base CCLayer):
Here v means vertex position and t - texture coordinates. You need to set correct texture coordinates for four corner vertices of layer. For future if you will want to drag circle you will need to add some offset values to texture coordinates.

iOS OpenGL or CoreGraphics smooth rectangle drawing

I'm trying to draw a filled rectangle in the drawRect and the rotate it by 5 degrees. The problem is that when I rotate this rectangle, the edges look very jagged. I have the feeling that this needs some anti-alising (or something similar), but I can't find any good sources of more information.
Does anyone have a good hint?
It really isn't possible to have a nice, natural curve on a computer because if you look closely you will always see that it really isn't a curve, it's a jagged line of squares.
More answering your question, if you want your line to be softer, you could blur it with a CIFilter. Remember that when you rotate something by anything other than 90, 180, 270, or 360 degrees you will lose quality. Your rectangle doesn't need anti-aliasing until it's rotated, and I'm sure apple has written a beautifully complicated way to blend/antialias your context.
Probably the easiest way to do this is to draw the individual lines in your rect at the slant instead of rotate the rect after you draw it.

Fastest / most efficient way to draw moving speech bubbles on screen - CoreAnimation, Quartz2D?

I am adding some functionality to an iPhone app, and could use some help in picking the fastest / most efficient / best practice approach for solving this problem:
At the upper-half of my screen, I have speech bubbles (think comic book) that are UIImageViews translating across the screen (dynamic x & y position). It is a UIImageView because there is an image as the background of the speech bubble.
Each speech bubble has a matching image moving around the bottom of the screen (elsewhere in the layer tree)
I would like to draw a tail (that triangle bit from a speech bubble) so the point of the triangle is tracking the lower image, with the base of the triangle being attached to the bottom of the upper UIImageView. (technically the base doesn't have to be butted against, it can overlap as long as I can match the color of my background image to the triangle).
I have already done all the tracking & drawn a line with CGContextStrokePath methods, and now I am stuck on how to replace the line with a triangle.
I have looked at drawing a triangle in Quartz and filling it. My concern is the speech bubbles are repositioned every 1/10th of a second, and it looks like drawing just the line used for proof of concept had a pretty severe performance / visual smoothness impact.
One idea I have is to do the trigonometry myself, and stretch & rotate an image of a triangle to connect each of these speech bubbles with the lower spot. Something is telling me there is a more efficient / more elegant solution, but I am not able to see it looking through the documentation. Any help on how you have or would approach this issue is appreciated. Thanks.
If the speech bubbles are fixed in size, just use a static UIImage. Set the image view's layer.position property at the point of the triangle. Then you can use view animation to move the bubbles around.
If you need the speech bubbles to be different sizes, I'd create a resizeable image using resizableImageWithCapInsets. Then I'd do the same as above to position it.
If there was something special about the speech bubble that I could't achieve with either a static image or a resizable image, I'd probably create a custom CA Layer or layers to get the effect I wanted (Like a gradient layer with a shape layer as it's mask layer)