I'd like to do
... all in the touchesBegan method without any "pauses" in between. But it seems that it wont let me do that.
like this:
s1.animationDuration = 0.0f;
s1.center = touchedPoint;
s1.alpha = 1.0f;
s1.animationDuration = 1.0f;
s1.alpha = 0.0f;
full example here: https://gist.github.com/gregtemp/5086240
I know i could just move it to the touchesEnded method but I want to avoid doing that.
In your question you're asking how to:
... so that it can reappear at another place when you touch the screen.
Also, you want to do this in a single method...
I would suggest taking a different approach to working out this problem.
First, try to think of shapes as objects that are persistent until you delete or dispose of them. Basically, you can treat the object as a thing that's going to get passed around to various methods.
When you start thinking like this, then you can use the following technique to make the effect you're looking for:
#import "C4WorkSpace.h"
@implementation C4WorkSpace
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *t in touches) {
CGPoint touchPoint = [t locationInView:self.canvas];
[self createObjectAtPoint:touchPoint];
}
}
-(void)createObjectAtPoint:(CGPoint)newPoint {
C4Shape *s = [C4Shape ellipse:CGRectMake(newPoint.x-25,newPoint.y-25,50,50)];
s.userInteractionEnabled = NO;
[self.canvas addShape:s];
[self runMethod:@"fadeAndRemoveShape:" withObject:s afterDelay:0.0f];
}
-(void)fadeAndRemoveShape:(C4Shape *)shape {
shape.animationDuration = 1.0f;
shape.alpha = 0.0f;
[shape runMethod:@"removeFromSuperview" afterDelay:shape.animationDuration];
}
@end
What this does is: