Reputation: 726
I'm trying to animate a Cocos2d node and a UIKit view move like this:
-(void)someFunction {
[myCocosNode runAction:[CCMoveTo actionWithDuration:myTime position:cocosPoint]];
[UIView animateWithDuration:myTime animations:^{ myView.frame = CGRectMake(uiPoint.x, uiPoint.y, myWidth, myHeight); }];
}
But the UIKit view doesn't move at the same speed as the Cocos2d node, and they are in the same starting position going to the same ending position.
Any ideas?
Upvotes: 1
Views: 456
Reputation: 726
Found a solution that works for synchronizing movement by PhilM in this thread.
He attaches the UIView to a subclass of CCLayer and overrides setPosition:
to update the UIView
's position when the layer moves. Then using CCMoveTo
on the layer will synchronize the movement with the UIView
.
-(void)setPosition:(CGPoint)pos {
[super setPosition:pos];
CGRect frame = slider.frame;
frame.origin.y = frame.origin.y + ([self position].y - pos.y); // Changed this line a bit to get correct positioning
slider.frame = frame;
}
Thanks PhilM!
Upvotes: 1