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-30-2010, 06:55 PM   #14 (permalink)
smasher
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

Okay, stacking blocks. You had this line in your moveBlocks method, to stop the blocks when they reach the bottom of the screen:

Code:
if (newCenter.y > 420) {
We want to change that to this, which will trigger if we're touching the bottom *or* our new method returns true:
Code:
if (newCenter.y > 420 || [self isTouchingStoppedBlock:block]) {
"isTouchingStoppedBlock" is a method we need to write. It will return true if the current block is touching a stopped block (meaning the new block should stop too).

Code:
-(bool) isTouchingStoppedBlock:(UIImageView*)block{
	
	//create a new rectangle, based on the current block's frame
	CGRect lowerFrame = block.frame;

	//but slightly lower on the screen
	// "10" should be a constant: how far a block moves in one frame
	lowerFrame.origin.y = lowerFrame.origin.y+10; 

	//now check if this lower rectangle is touching any other stopped block.
	//if it's touching a stopped block, we return true.
	for (UIImageView* stoppedBlock in blockArray){

		if( CGRectIntersectsRect(lowerFrame.fame, stoppedBlock.frame) )
			return true;

	}

	return false;
}
I haven't compiled this code, so apologies for any typos. Let me know if it works.
__________________

Free Games!
smasher is offline   Reply With Quote
 

» Advertisements
» Online Users: 361
18 members and 343 guests
ADY, apatsufas, Dani77, Dattee, dcool, Desert Diva, HDshot, HemiMG, ilmman, leahov, mer10, michelle, nobre84, Robiwan, smithdale87, thh022, vogueestylee
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,877
Threads: 89,222
Posts: 380,724
Top Poster: BrianSlick (7,129)
Welcome to our newest member, peterkessler45
Powered by vBadvanced CMPS v3.1.0

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