tags:

views:

81

answers:

3

hi all, I am trying to rotate my object like shakes dice. please suggest simplest way to implement it in my iphone application. Any kind of sample code or documentation.

thanks

deepika

+1  A: 

If you want to do this without using OpenGL you can use a UIImageView and the set a series of animation images. By creating a series of images you can create a "rolling dice" effect. Here is an example of how to do this:

// create a UIImageView
UIImageView *rollDiceImageMainTemp = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rollDiceAnimationImage1.png"]];

// position and size the UIImageView
rollDiceImageMainTemp.frame = CGRectMake(0, 0, 100, 100);

// create an array of images that will represent your animation (in this case the array contains 2 images but you will want more)
NSArray *savingHighScoreAnimationImages = [NSArray arrayWithObjects:
                                                [UIImage imageNamed:@"rollDiceAnimationImage1.png"], 
                                                [UIImage imageNamed:@"rollDiceAnimationImage2.png"], 
                                                nil];

// set the new UIImageView to a property in your view controller
self.viewController.rollDiceImage = rollDiceImageMainTemp;

// release the UIImageView that you created with alloc and init to avoid memory leak
[rollDiceImageMainTemp release];

// set the animation images and duration, and repeat count on your UIImageView
[self.viewController.rollDiceImageMain setAnimationImages:savingHighScoreAnimationImages];
[self.viewController.rollDiceImageMain setAnimationDuration:2.0];
[self.viewController.rollDiceImageMain.animationRepeatCount:3];

// start the animation
[self.viewController.rollDiceImageMain startAnimating];

// show the new UIImageView
[self.viewController.view addSubview:self.rollDiceImageMain];

You can modify the creation and setup including the size, position, number of images, the duration, repeat count, etc as needed. I've used this feature of UIImageView to create simple animation effects and it works great!

Please let me know if you try this and if it works for your needs. Also, post any follow up questions.

Bart

Bart Gottschalk
A: 

Hello Bart, nice your example, but do you think it's possible to rotate / control the rotation with touch gesture ?

Hermann