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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

Thread: Random Rocks
View Single Post
Old 02-16-2010, 01:30 AM   #50 (permalink)
Sesa
Registered Member
 
Join Date: Nov 2009
Posts: 91
Sesa is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
You're using beginAnimations/commitAnimations to animation an image from the top of the screen to the bottom, right? And then you're checking for collisions once, right after you start the animation.

In my experience CGRectIntersectsRect and beginAnimations/commitAnimations do not mix well. flakeImage.frame will return the endpoint of the animation, not the real current position of the flake. I would pick a reasonable framerate like 15 or 20 FPS and update the positions yourself, without using beginAnimations/commitAnimations.

I also don't see an array of flakes. CheckCollision needs to loop through the array of flakes and check each one against the elephant.

Code:
Ohh, Okay, This is my new code, but it dosent work either :( 

@synthesize myRock, meteorArray; 

-(void)viewDidLoad {
	
	
	[self createMeteors];
	
	[NSTimer scheduledTimerWithTimeInterval:(0.1) target:self selector:@selector(moveMeteors) userInfo:nil repeats:YES];
	
	[super viewDidLoad];
}


-(void)createMeteors{
	
    if (meteorArray==nil){
		meteorArray = [[NSMutableArray alloc] init];
    }
	
    UIImage *meteorImage = [UIImage imageNamed:@"STone.png"];
    UIImageView *newView;
	
    for (int i = 0; i< 3; i++){  //creates meteors
        newView= [[UIImageView alloc] initWithImage: meteorImage];
		
        //pick a position *above* the top of the screen
		int x = arc4random()%320; 
        int y = -arc4random()%480;
		double scale = 1 / round(random() % 100) + 1.0;
		double speed = 1 / round(random() % 100) + 1.0;
        newView.center = CGPointMake (x,y);
		
		
		
        [self.view addSubview: newView]; //adds meteors as subviews
        [meteorArray addObject: newView]; //add to array
        [newView release];
    }
	
}

-(void)moveMeteors{
	
	for (UIImageView* myRock in meteorArray ){
		
		//move new center down
		CGPoint newCenter = myRock.center;
		newCenter.y = newCenter.y +10;
		
		if (newCenter.y > 480){ // if off the bottom
			newCenter.y=0;   //pop to top
			newCenter.x = arc4random()%320;  //and pick new x position
		}
		
		myRock.center = newCenter;
	}
}

Last edited by Sesa; 02-17-2010 at 12:43 AM.
Sesa is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,478
Threads: 94,040
Posts: 402,627
Top Poster: BrianSlick (7,978)
Welcome to our newest member, Garnitomar
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:37 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.