-1

I am trying to make graphics move randomly in cameraview. Is there any way that I can get the balls moving in camera view? Or any tutorials that any one of you may refer me to?

1 Answers1

0

To do so, you will need to implement your own camera view: make UIViewController class, set UIImagePicerControllerSelegate to it, implement all necessary methods to make imagePicker work, set useCustomInterface property to "NO" and then, add any sub views to your custom camera. You may also make them move as you like.

In 5 words, implement your own custom camera. Here is poplar question about what you need: iPhone: Camera Preview Overlay

Community
  • 1
  • 1
SentineL
  • 4,682
  • 5
  • 19
  • 38
  • How do I add a subview into my view controller? – Wu Chin Kwang Nov 15 '11 at 08:53
  • As usual. You may add it useing interface builder, or pragramatically: [self.view addSubView:(your view/image/button here, anything, what is UIView subclass)]; – SentineL Nov 15 '11 at 09:37
  • I am able to place the images of the balls, but I have no idea how to program them to move. I have no idea where to place the codes that moves the balls around. – Wu Chin Kwang Nov 16 '11 at 02:48
  • `- (void)viewDidLoad { [super viewDidLoad]; pos = CGPointMake(5.0,4.0); } -(IBAction)start { [startButton setHidden:YES]; randomMain = [NSTimer scheduledTimerWithTimeInterval:(0.03) target:self selector:@selector(onTimer) userInfo:nil repeats:YES]; }` – Wu Chin Kwang Nov 16 '11 at 02:51
  • `-(void)checkCollision { if ( CGRectIntersectsRect(player.frame, enemy.frame)) { [randomMain invalidate]; [startButton setHidden:NO]; CGRect frame = [player frame]; frame.origin.x = 137.0f; frame.origin.y = 326.0; [player setFrame:frame]; CGRect frame2 = [enemy frame]; frame2.origin.x = 137.0f; frame2.origin.y = 20.0; [enemy setFrame:frame2]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You Lost!" message:[NSString stringWithFormat:@"You were Hit! Try again"] delegate:nil` – Wu Chin Kwang Nov 16 '11 at 02:52
  • `-(void)onTimer { [self checkCollision]; enemy.center = CGPointMake(enemy.center.x+pos.x , enemy.center.y+pos.y); if (enemy.center.x > 320 || enemy.center.x < 0) pos.x = -pos.x; if (enemy.center.y > 480 || enemy.center.y < 0) pos.y = -pos.y; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *myTouch = [[event allTouches] anyObject]; player.center = [myTouch locationInView:self.view]; }` – Wu Chin Kwang Nov 16 '11 at 02:54
  • it is difficult to explane this in few words. You need better understanding of coding on objective-c. It's all up to you to choose where to place it: there is many ways to do what you whant, but in each of them, you will need to set up different things. You can implement your logic in your camera view class, but it will be ugly. You can do it in any other class, but you will need to implement some delegate methods. And so on. I cant tell you best way for your case to do this, becouse we think different, and I didn't see your code. – SentineL Nov 16 '11 at 04:05