views:

319

answers:

3

Hello,

I would like to draw a image on the screen where ever the user touches.

I can't figure out how to do it.

Please help

thank you!

+2  A: 

You'll have to be creative on that one, you would have to catch the users touch points and (As the user is touch and moving about the screen) draw a point, line, circle, or image on the main object/view you are using. If you want to save the screen as an image you can use grab a snapshot of the application or view and store it locally.

Apple's got a simple application that does this, http://developer.apple.com/iphone/library/samplecode/GLPaint/Introduction/Intro.html. Once you download it, you can see how it catches the touch points and paints the lines. Just modify what it paints.

Hope I helped, Apple Development is such a Grey area to me.

Justin
Oh and to dynamically create images look at the GLSprite Sample code, http://developer.apple.com/iphone/library/samplecode/GLSPrite/Introduction/Intro.html. Your basically creating textures and adding the image to where the user clicks. Hope it helps!
Justin
A: 

Hi

Same issue here. I already used it. But i could not yet figure out how to save GLPaint. It uses Windows View rather UIView... so little tedious to customize.

Jay
+1  A: 

Tada!!!

With Images:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event {

UITouch *touch = [touches anyObject];
touchPoint = [touch locationInView:self.view];

CGRect myImageRect = CGRectMake(touchPoint.x, touchPoint.y, 20.0f, 20.0f); 
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"YourImage.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];

}

This code will draw an image wherever you touch!!

I couldn't test it on a device yet, but i believe it would lag just a tiny bit. (because of many images on screen)

With Quartz:

The second way is to use Quartz, try this link:http://www.ipodtouchfans.com/forums/showthread.php?t=132024

DailyDoggy