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 Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-22-2010, 12:10 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 14
Glych002 is on a distinguished road
Default multiple view creation and removal

Hi.
This is what I am trying to do. I am making a game that shoots by pressing a fire button. I want an image to be created every time the button is pressed. That part is easy. The problem is how do I track images so I can remove them individually?

What I am finding is that if I removeFromSuperview with a timer, all the views are removed including the ones that have just been created.

Is there a way to number views or images with a tag number or something so I can remove any view/image I need to.

For example: User presses the shoot button ten times and ten images come out. Now the enemy only touches images 4, 5, and 6, then those three images return a unique number so I can remove them and the rest continue on their paths without being removed.



Code:
CGRect myImageRect = CGRectMake(-x + Xposition,-y + Yposition, weaponSriteSize, weaponSriteSize);
    CGRect myImageRect1 = CGRectMake(number / num, number2 / num, weaponSize, weaponSize);
	cropView = [[UIView alloc] initWithFrame:myImageRect];
	UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect1];
	[myImage setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",weaponImage]]];
    
	myImage.opaque = YES; // explicitly opaque for performance
    cropView.clipsToBounds = YES;
	[cropView addSubview:myImage];
    
    [weaponDistance addSubview:cropView];
    
	[myImage release];
    [cropView release];

    
    
    
    [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(weaponStop) userInfo:nil repeats:NO];
      
    
}
- (void)weaponStop {
    
    [cropView removeFromSuperview];
    
   
}
I have removed the code that moves the projectile/image for simplicity.
Glych002 is offline   Reply With Quote
Old 09-22-2010, 01:53 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

the "myImage" has a "tag" property, so you can set it to whatever integer value

then you can use [[cropView viewWithTag: someTagValue] removeFromSuperview] to remove an individual image
smithdale87 is offline   Reply With Quote
Old 09-22-2010, 03:57 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 14
Glych002 is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
the "myImage" has a "tag" property, so you can set it to whatever integer value

then you can use [[cropView viewWithTag: someTagValue] removeFromSuperview] to remove an individual image
Awesome, perfect, thanks!

I knew it was something easy but I just could not figure it out.

Last edited by Glych002; 09-22-2010 at 05:37 PM.
Glych002 is offline   Reply With Quote
Reply

Bookmarks

Tags
image, sprites, tag

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: 349
12 members and 337 guests
2ndSegment, cgokey, djohnson, Domele, Hamad, markuschow, mistergreen2011, Objective Zero, pungs, revg, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

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