★ TouchArcade needs your help. Click here to support us on Patreon.

Image View Tap object make it disappear HELP!

11-26-2009, 11:24 PM
#1
Joined: Nov 2009
Posts: 1
Image View Tap object make it disappear HELP!

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.
11-26-2009, 11:28 PM
#2
Joined: Sep 2009
Posts: 5,678
Coding is so incredibly complicated....lol
11-27-2009, 01:11 AM
#3
Joined: Dec 2008
Location: The Land of The Rising Sun
Posts: 146
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);
}

Developer of Petri. Available now on the iTunes Store.

These days I work with Tonchidot on Sekai Camera.