Reputation: 13
I am trying to get 'luke' to jump over an object to ensure that the game does not end, which he does but even if he avoids the object the game still ends, as if luke had not left his original location during the animation.
I used the UIView animateWithDuration in -(void)touchesBegin
to try to achieve this.
[UIView animateWithDuration:3
animations:^
{
luke.center = CGPointMake(luke.center.x +0, luke.center.y -60);
}
completion:^(BOOL completed)
{
if (completed)
{
[UIView animateWithDuration:3
animations:^
{
luke.center = CGPointMake(luke.center.x +0, luke.center.y +60);
}];
}
I am also using CGRectIntersectsRect
to tell me when the two objects collide
-(void)collision {
if (CGRectIntersectsRect(luke.frame, smallboulder.frame)) {
[self endgame];
}
if (CGRectIntersectsRect(luke.frame, largeboulder.frame)) {
[self endgame];
}
if (CGRectIntersectsRect(luke.frame, cactus.frame)) {
[self endgame];
}
finally can i use an animation set up as a NSArray
to show movement when jumping.
Many thanks
JP
Upvotes: 1
Views: 583
Reputation: 57050
When using UIView
animation methods to animate various properties, the animation is actually performed on something called the presentation layer. But when you use the view's frame
accessor, it accesses the model layer (rather than the presentation layer), which holds the latest values (so it holds the designated frame after animation).
You should check for "luke"'s location using luke.layer.presentationLayer.frame
.
Upvotes: 1