Image View Tap object make it disappear HELP!

Discussion in 'Public Game Developers Forum' started by slimbonez7, Nov 27, 2009.

  1. slimbonez7

    slimbonez7 New Member

    Nov 27, 2009
    1
    0
    0
    Hi,

    I am trying to make an obj dissabear when i tap it, and appear back in the center. it is a game. The object starts in the center of the screen, then when u tap to begin, it starts going in a random direction.

    I need to tap that object and have it return to the center. possibly play a sound when tapped too. I am making it in a view based app styple. using an image view for the obj,not sure if i use a button or something instead.

    Here is what i have for my code.

    -(void) gameLoop {
    if(gameState == kGameStateRunning) {

    obj.center = CGPointMake(obj.center.x + objVelocity.x , obj.center.y + objVelocity.y);

    if(obj.center.x > self.view.bounds.size.width || obj.center.x < 0) {
    objVelocity.x = -objVelocity.x;
    }

    if(obj.center.y > self.view.bounds.size.height || obj.center.y < 0) {
    objVelocity.y = -objVelocity.y;
    }
    } else {
    if(tapToBegin.hidden) { tapToBegin.hidden = YES;
    }

    It right now just goes up and down bouncing off the edges of the screen.
    If u want to email me at.
     
  2. d1

    d1 Well-Known Member

    Sep 19, 2009
    5,678
    5
    0
    Coding is so incredibly complicated....lol
     
  3. I think the first thing you want to do is look up the functions "touchesBegan" or "touchesEnded" in the documentation. These are the functions that are called when the user touches the screen. Below is just an example, but it looks like you want to do something like this:

    Code:
     - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        obj.position = CGPointMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0);
    }
    
     

Share This Page