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

View Single Post
Old 01-28-2010, 01:44 PM   #4 (permalink)
iPhoneDevelopment
Banned
 
Join Date: Dec 2009
Posts: 61
Default

I have realised that the current code that I am using is causing the blocks to all fall to the bottom of the screen, whereas what I want is for the blocks to pile on top of themselves. I changes the code in the example smasher gave me to try to implement this, but it does not seem to have worked. The code I am currently using is posted below, but when built no blocks are created or animated down the screen.

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	self.gameState = kGameStatePaused;
	blockVelocity = CGPointMake(kBlockSpeedX, kBlockSpeedY);
	[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
	[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(blockCollision) userInfo:nil repeats:YES];
}

-(void)gameLoop {
	if(gameState == kGameStateRunning) {
		
		UIImage *blockImage = [UIImage imageNamed:@"block.png"];
		
		block= [[UIImageView alloc] initWithImage: blockImage];
		
		int x = arc4random()%320; 
		int y = -100;
		block.center = CGPointMake (x,y);
		
		block.center = CGPointMake(block.center.x + blockVelocity.x, block.center.y + blockVelocity.y);
		
		[self.view addSubview: block];
		[block release];
}}

-(void)blockCollision {
	
	CGPoint newCenter = block.center;
	if (newCenter.y > 420){
		newCenter.y = 420;
		UIImage *blockImage = [UIImage imageNamed:@"block.png"];
		
		block= [[UIImageView alloc] initWithImage: blockImage];
		
		int x = arc4random()%320; 
		int y = -100;
		newCenter = CGPointMake (x,y);
		
		[self.view addSubview: block];
		[block release]; }

	if (CGRectIntersectsRect(block.frame, block.frame)){
		newCenter.y = -10;
		UIImage *blockImage = [UIImage imageNamed:@"block.png"];
		
		block= [[UIImageView alloc] initWithImage: blockImage];
		
		int x = arc4random()%320; 
		int y = -100;
		newCenter = CGPointMake (x,y);
		
		[self.view addSubview: block];
		[block release]; }
	block.center = newCenter;
		
	}
Again, any help would be much appreciated!!

Thanks

Cam
iPhoneDevelopment is offline   Reply With Quote
 

» Advertisements
» Online Users: 354
19 members and 335 guests
ADY, apatsufas, BdR, catedawn, fiftysixty, F_Bryant, iDifferent, john love, jorge599, kampftrinker, ligerligerliger, mer10, mizzytheboy, Naughty_Ottsel, nobre84, RoryHarvey, themathminister
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,876
Threads: 89,225
Posts: 380,701
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jorge599
Powered by vBadvanced CMPS v3.1.0

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