I am trying to animate balloons which are actually images. To do so, I have created sub class of CALayer which shows an image in its content and finally multiple objects of this sub class will added to view of viewcontroller.
Once I call a function "bounce" over the each object of this subclass. The position of all these layers (balloons) start animating in such a way that it create bounce effect around the view boundaries. It keeps on changing the position of layers until it stop it by calling method "stopBouncing".
Now the problem is, there is some flickering in layers and performance is also not good if the count of balloons is high.
Would be really grateful if someone can help me regarding efficient implementation of such requirement.
Note : This is for iPhone.
A piece of whole code:
-(void)bounce
{
self.position=CGPointMake(self.position.x+self.moveOffset.x,self.position.y+self.moveOffset.y);
if(self.position.x>self.maxBoundary.x || self.position.x<self.minBoundary.x)
{
self.moveOffset.x=-self.moveOffset.x;
}
if(self.position.y>self.maxBoundary.y || self.position.y<self.minBoundary.y)
{
self.moveOffset.y=-self.moveOffset.y;
}
}
Here, moveOffset is the the distance on x axis and y axis which would be traveled by layer in a time interval.