Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-07-2010, 10:36 AM   #1 (permalink)
I like pizza
 
Picoman's Avatar
 
Join Date: Jul 2009
Location: Scotland
Age: 27
Posts: 314
Default CABasicAnimation with transform.rotation

Hey,

I have looked through about 12 pages of Game Development and couldnt find a solution, so here is my problem.

Im trying to create a color wheel that rotates to the next color when navigation button is pressed.

So, everything to do with navigation is fine, got that down pretty good by now but i am using something new to me and its driving me mental.

The things new to me are the <QuartzCore/QuartzCore.h> framework and CABasicAnimation with transform.rotation. So, i figured out how to make a single image spin, which is cool, but not what i want yet.

I can get the wheel to spin say 90 degrees then load the next view, (with the buttons and labels ect.) but when the wheel spins again there is an image of the wheel behind the animation! I cant get rid of it without doing removeFromSuperview, (i cant seem to get it back again after that.)

Here is my code:

Code:
	// This bit removes a view with a static image of the color wheel at start position.
	...[flip1View1 removeFromSuperview];
    	
     UIImage *image = [UIImage imageNamed:@"Rainbow4.png"];
	
	UIImageView *imgView =[[UIImageView alloc] initWithImage:image];
	[imgView setFrame:(CGRect){{0,0},image.size}];
	[imgView setCenter:(CGPoint){0,240}];
	[self addSubview:imgView];
	
	// So i have got my image on screen and its about to spin 90 degrees.

	CABasicAnimation * rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
	rotationAnimation.fromValue = [NSNumber numberWithFloat:0];
	rotationAnimation.toValue = [NSNumber numberWithFloat:((90*M_PI)/180)];
	rotationAnimation.duration = 2;
	
	[imgView.layer addAnimation:fullRotation forKey:@"360"];

	  [self performSelector:@selector(loadNextView) withObject:nil afterDelay:2.00];
}

		// When 2 seconds have passed, load the next view. The next view has a static image of the color wheel rotated 90 degrees, its pretty seamless.

- (void) loadNextView {
	[self addSubview:flip1View2];
}
When using this code, an image of the color wheel appears in the background of the next spin. (Only time it works is the first time.)

I would like to know how to have it so the First View loads... Next(Button Press)... Animation... Second View loads... Next(Button Press)... Animation... ect. If i use removeFromSuperview then i cannot use the animation again...

Any ideas on how to release the animation so that it is loaded fresh everytime?
This way i would be able to give the animation a different start position for the direction they are navigating.

Thank You

Alex
__________________
Picoman is offline   Reply With Quote
Old 01-07-2010, 03:12 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 7
Default Re:

Maybe try to declare your "CABasicAnimation * rotationAnimation" instance within the header file. Then within the -(void)viewDidLoad method add your "rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];", and possibly the rest of the setup of it.

Also do you plan on rotating it again 90 more degrees after you rotate it once? If you do, declare an int called numOfTimes, and in the viewDidLoad method set it to "1" and then within your method at the end add "numOfTimes++;" then within your "rotationAnimation.toValue = [NSNumber numberWithFloat(90*M_PI)/180)];" change the ((90*M_PI)/180) part to (((90*numOfTimes)*M_PI)/180) so that because you set the rotationAnimation.fromValue to 0 so every time you execute the animation it's direction is equal to 0 at the beginning and then you rotate the number of degrees afterwards.
SDKTutor is offline   Reply With Quote
Old 01-09-2010, 09:04 PM   #3 (permalink)
I like pizza
 
Picoman's Avatar
 
Join Date: Jul 2009
Location: Scotland
Age: 27
Posts: 314
Default

Thanks for your reply. It got me thinking, because each view is responsible for a certain amount of rotation, either backwards or forwards navigation, i was able to use code such as this:

Code:
          rotationAnimation.fromValue = [NSNumber numberWithFloat:4.50719755];
	  rotationAnimation.toValue = [NSNumber numberWithFloat:5.40719755];
And between the rotations, the static image with this:

Code:
imgView.transform = CGAffineTransformMakeRotation(5.40719755);
All this is done with the same image file which is nice for the resource folder size!

My image had alpha, which is why i could see the images in the background persisting after animation.

As a work around, i replaced the alpha with color however, because im rotating a 800x800 i am experiencing slowdown, even on the 3GS.

Does anyone know how to remove the unwanted images behind my rotation animation? Or is rotating an 800x800 image over and over again impossible without slowdown?

Thanks
__________________
Picoman is offline   Reply With Quote
Reply

Bookmarks

Tags
cabasicanimation, iphone, quartz, rotation, transform

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 254
21 members and 233 guests
ADY, bookesp, ckgni, dacapo, Dani77, DarkAn, Davey555, Desert Diva, HemiMG, iDifferent, jakerocheleau, JasonR, LEARN2MAKE, nobre84, prchn4christ, Rudy, ryantcb, Speed, themathminister, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,766
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:39 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0