Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
hi I tried for a while (I was trying to track the position to detect collisions between objects). long story short: you can't (or uptil now nobody has been able to tell me how
I tried accessing the values during animations, putting observers etc etc
the problem is that you delegate the animation to Core Animation (I'm guessing) like in the move me example of apple.
then its CA that handels everything. it doesn;t seem to physically move your layer. (in you code at the end you have to do something like whatIsAnimated.center = layerAnimated.center; (if you moving an object)
if your trying something simple like changing the animation while its executing then just end it and restart a new one
if your creating something much more precise like a game with moving object, collisions etc then you have to major choices: - take out the big guns and use OpenGl ES - create your own moveable object
both methods are similar (since the logic is the same) it really depends on what type of app you want and what are your overall goals
I don't think without some code and/or some general goal of your animation, anybody will be able to help you more
hope this helps
jason rogers
We all have to go down this same road.
You liked it when the ones in front of you helped.
well I'm having a layer moving from A to B. Let's say this way: When the user taps the screen, a dot has to appear exactly there, where the layer is at this precise moment.
I'm seeing no other way, than looking into the future.
That means, I'm going to calculate the path and cut it into little bits and put the bits into an array indexed with a global timestamp that I made on my own, coupled with the number of loops my main timer does....pretty crappy...
Yes I thought you talked about the UIView but I don't have an UIView that I'm animating. It's just layer.position = CGPointMake....during an [UIView beginAnimation...
Well I tried with the array and calculating the positions of the layer into the future, but it just isn't exact. I really need the current position of the layer. It is the same, when animating (via UIView beginAnimation) an UIView. Its also not possible to get its current position.
So how can I implement my own animation? Any help?
Does this work for you or is there something I'm missing? For simplicity, the code is located in a view controller in a skeleton Xcode project--you can move it around according to your needs and do hit testing once you get the current position.
- (void)viewDidLoad { [super viewDidLoad];
layer = [CALayer layer]; // Declare layer as an ivar in your .h file UIImage *image = [UIImage imageNamed:@\"YourSpriteImage.png\"]; layer.contents = (id)image.CGImage; layer.bounds = CGRectMake(0, 0, image.size.width, image.size.height); [self.view.layer addSublayer:layer];
I'm pretty sure that somewhere down the line you are using a derivative of a UIView surely a UIImageVIew to display what your moving, and that the layer your refering to is the view layer that you get when doing something like this
(code from the move me example of the apple website).
to build your own animation its pretty straight forwards (and a classic algorithm for game programing ^^)
create a loop that iterates at a high enough speed (human eye distinguishes around 23 FPS so you need at that, 3D engines to make clean animations work on anideal goal of 60FPS)
the basic physics : speed = distance / time
to create your animation you need to add a unit of movement usually referred as delta. at each iteration you add this delta to the position of the object you want to animate. the delta represents the distance your object has moved since the last iteration.
to go down this road (especially on a mobile platform) you have to optimize you code and limit the number of test you do.
thats the basics
jason
We all have to go down this same road.
You liked it when the ones in front of you helped.
I'm pretty sure that somewhere down the line you are using a derivative of a UIView surely a UIImageVIew to display what your moving, and that the layer your refering to is the view layer that you get when doing something like this
(code from the move me example of the apple website).
to build your own animation its pretty straight forwards (and a classic algorithm for game programing ^^)
create a loop that iterates at a high enough speed (human eye distinguishes around 23 FPS so you need at that, 3D engines to make clean animations work on anideal goal of 60FPS)
the basic physics : speed = distance / time
to create your animation you need to add a unit of movement usually referred as delta. at each iteration you add this delta to the position of the object you want to animate. the delta represents the distance your object has moved since the last iteration.
to go down this road (especially on a mobile platform) you have to optimize you code and limit the number of test you do.
thats the basics
jason
I can't beliEVE it, it's just soo oldschool. Of course I could code something like this, but especially when I'm trying to have this EaseInOut Curve it is going to be just stupid work to do on your own...I don't blame you, but Apple...but...well wdn's code somehow works...and I'm pretty sure that my problem with the layer jumping back to the start is some idiotic mistake I made...lets see...
I'm pretty sure that somewhere down the line you are using a derivative of a UIView...
Unless CAAnimation is doing something behind the scenes I'm not aware of (which would be odd since it works only with layers), the only UIView is the container view of the view controller.
Kroupy said:
the only thing is...when the animation is done, it jumps back to the start....
This is because only the presentation layer changes from the animation. The model layer hasn't changed when the animation is done. Simply update your layer.position property when the animation is finished.
Does this work for you or is there something I'm missing? For simplicity, the code is located in a view controller in a skeleton Xcode project--you can move it around according to your needs and do hit testing once you get the current position.
- (void)viewDidLoad { [super viewDidLoad];
layer = [CALayer layer]; // Declare layer as an ivar in your .h file UIImage *image = [UIImage imageNamed:@\"YourSpriteImage.png\"]; layer.contents = (id)image.CGImage; layer.bounds = CGRectMake(0, 0, image.size.width, image.size.height); [self.view.layer addSublayer:layer];
This code worked fine for me prior to 3.2 and 4.0 versions of the SDK (i.e. up to 3.1.3)... But it seems that Apple has changed something in the internal implementation and now (in 3.2 or 4.0) [[layer presentationLayer] frame] function doesn't return the CURRENT location/size of the layer anymore... The value just doesn't get updated properly and always equals the initial position of the object (or final, don't remember exactly) being animated. Does anybody experience this problem? I've just tried iPhone SDK 4 Beta 2, which was released yesterday - and it still doesn't work...
I wanted to confirm the problem before reporting a bug to Apple.
Same problem here. Rotation values taken from the presentationLayer seem to be okay, but using [(CALayer*)(aView.layer.presentationLayer) position] returns some weird values starting with 3.2 ... anyone any idea how to fix this?
Replies
I tried for a while (I was trying to track the position to detect collisions between objects).
long story short: you can't (or uptil now nobody has been able to tell me how
I tried accessing the values during animations, putting observers etc etc
the problem is that you delegate the animation to Core Animation (I'm guessing) like in the move me example of apple.
then its CA that handels everything. it doesn;t seem to physically move your layer. (in you code at the end you have to do something like whatIsAnimated.center = layerAnimated.center; (if you moving an object)
if your trying something simple like changing the animation while its executing then just end it and restart a new one
if your creating something much more precise like a game with moving object, collisions etc then you have to major choices:
- take out the big guns and use OpenGl ES
- create your own moveable object
both methods are similar (since the logic is the same) it really depends on what type of app you want and what are your overall goals
I don't think without some code and/or some general goal of your animation, anybody will be able to help you more
hope this helps
jason rogers
You liked it when the ones in front of you helped.
So think about the ones behind you.
---
try, try again, try some more, then ask.
once you asked, continue trying until you find a
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomesure,
well I'm having a layer moving from A to B. Let's say this way: When the user taps the screen, a dot has to appear exactly there, where the layer is at this precise moment.
Yes it is a game.
But it's not worth OpenGL
Thanks!
Me
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomewell then if you want the cheap fix try something like this
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event{
animated.frame = [[animated.layer presentationLayer] frame];
[playerShip.layer removeAnimationForKey:@\"animate\"];
//display your point
//restartyour animation
}
cheap fix because you stop your animation to make your system update the position of the layer before restarting the animation
if you don't have a lot more animation then that should do the trick
You liked it when the ones in front of you helped.
So think about the ones behind you.
---
try, try again, try some more, then ask.
once you asked, continue trying until you find a
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThe layer itself is animated. I have layer.frame but no animated.layer?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI'm seeing no other way, than looking into the future.
That means, I'm going to calculate the path and cut it into little bits and put the bits into an array indexed with a global timestamp that I made on my own, coupled with the number of loops my main timer does....pretty crappy...
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomeby animated I was talking about the UIView your animating
You liked it when the ones in front of you helped.
So think about the ones behind you.
---
try, try again, try some more, then ask.
once you asked, continue trying until you find a
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomethanks
Yes I thought you talked about the UIView but I don't have an UIView that I'm animating. It's just layer.position = CGPointMake....during an [UIView beginAnimation...
How can I do "my own animation?"
Thanks!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSo how can I implement my own animation? Any help?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- (void)animatePlacardViewToCenter{
CALayer *welcomeLayer = placardView.layer;
...
(code from the move me example of the apple website).
to build your own animation its pretty straight forwards (and a classic algorithm for game programing ^^)
create a loop that iterates at a high enough speed (human eye distinguishes around 23 FPS so you need at that, 3D engines to make clean animations work on anideal goal of 60FPS)
the basic physics : speed = distance / time
to create your animation you need to add a unit of movement usually referred as delta. at each iteration you add this delta to the position of the object you want to animate. the delta represents the distance your object has moved since the last iteration.
to go down this road (especially on a mobile platform) you have to optimize you code and limit the number of test you do.
thats the basics
jason
You liked it when the ones in front of you helped.
So think about the ones behind you.
---
try, try again, try some more, then ask.
once you asked, continue trying until you find a
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomethe only thing is...when the animation is done, it jumps back to the start....
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThanks, it works perfectly!
To all who read this toppic: Use the code writen by wdn.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeMac Mini 2,26GHz - 4 GB
iPhone 3GS - 32 GB :: iPod Touch - 16 GB :: iPod Shuffle - 4 GB
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeBut it seems that Apple has changed something in the internal implementation and now (in 3.2 or 4.0) [[layer presentationLayer] frame] function doesn't return the CURRENT location/size of the layer anymore... The value just doesn't get updated properly and always equals the initial position of the object (or final, don't remember exactly) being animated. Does anybody experience this problem? I've just tried iPhone SDK 4 Beta 2, which was released yesterday - and it still doesn't work...
I wanted to confirm the problem before reporting a bug to Apple.
Thanks to everyone,
Funbit
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome