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 > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-29-2011, 06:57 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 6
nihilvex is on a distinguished road
Default Remove same objects on touch

Greetings!

I'm having an issue with removing objects from superview if they are from the same type. It's a grid 6 x 6 with lets say 3 different types of objects and what I'm trying to accomplish is on touch all neighbour objects from same type to disappear.

Code:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch* touch = [touches anyObject];
		CGPoint touchXY = [touch locationInView:self.view];
		touchedX = (touchXY.x+startX)/CELL_XSIZE;	
		touchedY = (touchXY.y+startY)/CELL_YSIZE;
		   
		
	originValue=myCells[touchedY][touchedX];
	
	
memset(myCellsTmp, sizeof(myCellsTmp), 0);
	                       	
	int x,y;		
	for (y=0; y<GRID_HEIGHT; y++) {
	
		for (x=0; x<GRID_WIDTH; x++) {
		
			myCellsTmp[y][x] = 0;
							 
		   
           if (myCells[y][x] == originValue)  {
				
				myCellsTmp[y][x]=1; 
			   						  
				if (myCellsTmp[y][x] == 1 && (y>0 && myCellsTmp[y-1][x] == 1) || (y<5 && myCellsTmp[y+1][x] == 1) || (x>0 && myCellsTmp[y][x-1]==1) || (x<5 && myCellsTmp[y][x+1]==1)) { 
			
			
						[myCellsImages[y][x] removeFromSuperview];
				
			     }
			  }	
	
			}
	}
}
myCells is int [6][6] array that serves as a map. Object from type 1 is 1..type 2 - 2 ...ect
int myCellsTmp[6][6] is all 0 and what I'm doing there is all items from type same as the touched one turn into 1s.
myCellsImages contains the png's which the grid is loading and uses myCells as a map to that.

I believe that my second if is the reason I get messy results. I know there should be something more in it cause now it removes gems from same type but not necessarily being neighbours of the touched one.

Any help?

p.s. needless to say I'm new to programming
nihilvex is offline   Reply With Quote
Old 08-29-2011, 09:30 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 6
nihilvex is on a distinguished road
Default

nvm I kinda solved it by making myCellsTmp mark with 1s only the neighbors of the touched object, instead all of this type

thanks anyway!
nihilvex is offline   Reply With Quote
Reply

Bookmarks

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: 396
14 members and 382 guests
7twenty7, apatsufas, AppsBlogger, comicool, Creativ, Dalia, dansparrow, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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