Controls Question...
Hello, I've been designing a game for the iPhone I've got all the levels completed in xcode now i'm just programming everything. My question is, I was trying to do the controls via buttons on the screen when you push them the character moves, but every time i would try and hold the button down the character wouldn't continue to move. If anyone knows what i could do that would be great help

Impossible to tell without seeing the code, but I presume you're using TouchesBegan to send events to something that moves your character per frame. If this is the case, it will not work because TouchesBegan only fires on the frame you touch the screen.
What you want to do is have a BOOL that becomes true on TouchesBegan, and becomes false on TouchesEnded. You will have one of these per control. Every frame, if that BOOL is true, then you move the character.
What you want to do is have a BOOL that becomes true on TouchesBegan, and becomes false on TouchesEnded. You will have one of these per control. Every frame, if that BOOL is true, then you move the character.
Justin Ficarrotta
http://www.justinfic.com
"It is better to be The Man than to work for The Man." - Alexander Seropian
Thank-you for your response thats exactly what I was looking for

I've impletemented this using this same solution, I do have a problem however. If the user pressed and holds down a button, and then moves their finger out of the button area and then lets go the button will stay pressed. As other buttons maybe pushed at the same time, Im having a hard time working out which touch is which, so I need to somehow track that the first touch is moved out of the area, and not one of the other touches, if that makes sense? Any idea how to do this? Thanks!
Hey I'm really desperate now, i've got an IBAction when the user clicks the button it switches on a bool, then in the gameloop section i have it when the bool is true the character moves, can someone please show me some code how i would do the touches? at the moment i have IBAction walkLeft { } then switch on the bool can someone help me please? i'm desperate.
i did this for mine
i made an ibaction for when the user taps down on the button and a made an ibaction when the user releases the button. I also have it set in an ns timer so that when direction=kforward the character starts moving and when direction=kstopped he stops moving. I hope this helps if it dosn't i might be able to help you more.
Chris
Code:
- (IBAction)characterForward:(id)sender{
// walking=TRUE;
direction=kForward;
swipePic=kPicForward;
if (direction==kForward){
charWalking=[[NSMutableArray alloc] init];
for(int i=0;i<3;i++){
NSString *picname=[NSString stringWithFormat:@"charWalking%d.png",i];
UIImage *img=[UIImage imageNamed:picname];
if(img)[charWalking addObject:img];
}
[character setAnimationImages:charWalking];
[character setAnimationDuration:1.2f];
[character startAnimating];
}
- (IBAction)characterForwardEnd:(id)sender{
direction=kStopped;
bullet.center= CGPointMake(bullet.center.x+bulletpos.x,character.center.y);
//walking=FALSE;
[character stopAnimating];
}
i made an ibaction for when the user taps down on the button and a made an ibaction when the user releases the button. I also have it set in an ns timer so that when direction=kforward the character starts moving and when direction=kstopped he stops moving. I hope this helps if it dosn't i might be able to help you more.
Chris
That's it! it took me a few minutes to figure out the connections for the actions but it worked amazingly! thankyou so much!
No problem, this unfortunately will be my last post. Because no one can help on this forum all they can do is send links to google. it annoys me. if you need anymore help just send me a private message and i will give you my e-mail address.
chrism, you seriously need to develop a little thicker skin. diordna has a tendency to be a smart @ss from time to time. I for one would not like to see you leave so quickly.

I guess I overreacted. It just makes me so mad when someone spends more time making that stupid link than it would to help me out. So I guess I will stay. Thanks for talking me out of it LOL.
chrism Wrote:I guess I overreacted. It just makes me so mad when someone spends more time making that stupid link than it would to help me out. So I guess I will stay. Thanks for talking me out of it LOL.
Sweet! Good to know your staying! But I do agree ppl can be unhelpful but that's why I posted again on this thread lol and you came to the rescue lol thanks again!
No problem
can't wait to see your finished product

Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
UIView Subclass not displaying controls... | flipflop | 7 | 9,879 |
May 13, 2010 01:16 PM Last Post: flipflop |