Hi, Once again another problem has reared its ugly head! I created a basic animation using a UIImageView and wanted to expand on that by making the code more reusable as I want multiples of that animation displayed on the screen
My idea was to create a UIView class called explosionView.m and .h and write the UIImageView animation code there.
This is the init code within the explosionView.m UIView object file:
Code:
- (id)init {
UIImage *image = [UIImage imageNamed:@"RGB0001.png"];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
aExplosionView = [[UIImageView alloc] initWithFrame:frame];
[image release];
self.opaque = NO;
aExplosionView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"RGB0001.png"],
[UIImage imageNamed:@"RGB0002.png"],
[UIImage imageNamed:@"RGB0003.png"],
[UIImage imageNamed:@"RGB0004.png"],
[UIImage imageNamed:@"RGB0005.png"],
[UIImage imageNamed:@"RGB0006.png"],
[UIImage imageNamed:@"RGB0007.png"],
[UIImage imageNamed:@"RGB0008.png"],
[UIImage imageNamed:@"RGB0009.png"],
[UIImage imageNamed:@"RGB0010.png"],
[UIImage imageNamed:@"RGB0011.png"],
[UIImage imageNamed:@"RGB0012.png"],
[UIImage imageNamed:@"RGB0013.png"],
[UIImage imageNamed:@"RGB0014.png"],
[UIImage imageNamed:@"RGB0015.png"],
nil];
aExplosionView.animationRepeatCount = 1;
aExplosionView.animationDuration = 1;
aExplosionView.center = CGPointMake(0, 0);
[aExplosionView startAnimating];
return self;
}
and in my mainViewController.m I do this to create an instance of the explosionView class in viewDidLoad:
Code:
UIImage *image = [UIImage imageNamed:@"RGB0001.png"];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
explosionView *explo = [[explosionView alloc] initWithFrame:frame];
[image release];
explo.center = CGPointMake(100, 100);
[self.view addSubview:explo];
I have done this before with UIImages for non-animation images - but when I tried with this animating UIImageView, a black square where my animation should be displayed is displayed. No crash, no nothing. Just a black square. Not terribly useful!
Anyone know what's happening?
Thanks
Jetwilson