Very excited for my first post on SO!
I would like to create an animation like this in xcode
I am not having much luck with what CABasicAnimation has to offer.
Feels like I may need one of those fancy physics engines...(?)
How would one properly begin do this?
Thanks!
I would probably use NSBezierPath to create such an animation. I would create a path which I extended along the sine curve on each iteration, and stroke the path appropriately. If you give us more details about what you're attempting to do, we can give you more details about how to do it.
Exactly what you want.TFAnimation allows you to use customize timingFunction by set a closure to timeFunction of TFBasicAnimation.
The demo in github is exactly a Sin animation.It use a CAAnimationGroup combined linear CABasicAnimation in position x and TFBasicAnimation of Sin timeFunction in position y.
Related
Hey guys I'm working on a android game with libGDX, and I got a zoom problem here. It's basically a ski safari style 2D game, and I want to implement a zoom in/out effect as the height changing. Is that possible to work this out with OrthoGraphicCamera? Or shall I change the size of the objects in real time(because I still wanna keep the background in a fixed size)?
if Camera.zoom not solve your problem, you can use
batch unmodified to draw your backgroud, and use batch.getProjectionMatrix().cpy().scale (yourScaleVariableX, yourScaleVariableY, 0);
to simulate only the items that you want, varying varibles, not if you're looking hopefully help.
simple example:
variable Class
Matrix4 testMatrix;
float yourScaleVariableX;
float yourScaleVariableY;
example render method
.//
batch.begin();
yourBackground.draw...
batch.end();
batch.begin();
testMatrix = batch.getProjectionMatrix().cpy().scale (yourScaleVariable, yourScaleVariable, 0);
batch.setProjectionMatrix(testMatrix);
yourItem.draw..
batch.end();
I think it is more efficient, changing the matrix, which resize all objects.
I hope to explain well.
Edit
I did not realize when I wrote the answer, you can store save the original matrix, before editing it for later use, or use batch.setProjectionMatrix (camera.combined); to restore
I'm working on an iPad application and that's my problem:
I elaborated an algorithm to know if a point is inside a polygon, in an image. So I need when touching the Image, to know the coordinates of the touched point and then do an action using those coordinates (an NSLog to make the example easy), the problem is that I can't use an IBAction on an UIImageView, and so can't recover the point's coordinates. Thanks for any help
I think at first you have to make polygon which fit to your image. And then you can use touchesBegan:withEvent: to get the coordinate of touch point and judge whether the point is inside of polygon or not.
Here is similar question like yours.
How to get particular touch Area?
I think this is a little difficult work, so maybe you would better use cocos2d library which have collision judgement function.
http://box2d.org/forum/viewtopic.php?f=9&t=7487
But also I think iOS is well constructed for handling touch, so this is beneficial effort for you.
Is it possible to have a curve UISlider or is it just Horizontal and Vertical?
I've tried replacing the slider track with a curve image (though i already know hat it will not work because it is just a background), not working.
Is there a way that i could do that?
Take a look at custom controls (both of them are under MIT license):
MHRotaryKnob
Cocoacontrols
Github
DCKnob
Cocoacontrols
Github
I wrote this sample app to show how to use a Curve UIBezierPath and move an object through it
you can take a look at :
Curvy UISlider
I will try to update it.
No you can't do this with the UISlider, only in a straight line. You can rotate the whole slider to a degree you like with the transform property and use a function like CGAffineTransformMakeRotation. An example: How to use CGAffineTransformMakeRotation?.
You can also check out BezierSlider which allows you to customize the path and the selector.
This has already been asked at Add a magnifier in cocos2d games
But I didn't quite understand the answer. I am using the same tutorial Let's Spot It is using but I'm not sure where to put madhu's code. I also don't know what the runAction method looks like.
Thanks
Hmm... Cocos2d CCLens3D, makes the area that is set by the programmer to popup.. Please look at the example provided by cocos2d..
the codes:
id lens = [CCLens3D actionWithPosition:ccp(size.width/2,size.height/2) radius:240 grid:ccg(15,10) duration:0.0f];
[self runAction:lens];
self is the layer where your image should be..
ccp(size.width/2, size.height/2) should be changed to ccp(yourPosition.x, yourPosition.y), means the positions which you want the popUp to be at.. Radius is the size of the circle, duration is how long you want it to be, 0.0 meaning infinite.. grid just use the same values..
I would like to know how I can get the diameter (or radius) of an expanding circle animation at a at any point in time during the animation. I will end up stoping the animation right after I get the size as well, but figure I couldn't stop and remove it form the layer until I get the size of the circle.
For an example of how the expanding circle animation is implemented, it is a variation on the implementation shown in the addGrowingCircleAtPoint:(CGPoint)point method in the answer in the iPhone Quartz2D render expanding circle question.
I have tried to check various values on the layers, animation, etc but can't seem to find anything. I figure worse case I can attempt to make a best guess by taking the current time it is into its animation and use that to figure where it "should" be at based on its to and from size states. This seems like overkill for what I would assume is a value that is incrementing someplace I can just get easily.
Update:
I have tried several properties on the Presentation Layer including the Transform which never seems to change all the values are always the same regardless of what size the circle is at the time checked.
Okay here is how you get the current state of the an animation while it is animating.
While Rob was close he left out two pieces of key information.
First from the layer.presentationLayer.subLayers you have to get the layer you are animating on, which for me is the only sub layer available.
Second, from this sub layer you cannot just access the transform directly you have to do it by valueForKeyPath to get transform.scale.x. I used x because its a circle and x and y are the same.
I then use this to calculate the size of the circle at the time of the based on the values used to create the Arc.
I assume what you're trying to get to is the current CATransform3D, and that from that, you can get to your circle size.
What you want is the layer.presentationLayer.transform. See the CALayer docs for details on the presentationLayer. Also see the Core Animation Rendering Architecture.