Controls Question...

Apprentice
Posts: 19
Joined: 2009.03
Post: #1
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 Smile
Quote this message in a reply
Member
Posts: 338
Joined: 2004.07
Post: #2
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.

Justin Ficarrotta
http://www.justinfic.com
"It is better to be The Man than to work for The Man." - Alexander Seropian
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2009.03
Post: #3
Thank-you for your response thats exactly what I was looking for Smile
Quote this message in a reply
Member
Posts: 94
Joined: 2008.08
Post: #4
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!
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2009.03
Post: #5
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.
Quote this message in a reply
Member
Posts: 43
Joined: 2009.04
Post: #6
i did this for mine

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
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2009.03
Post: #7
That's it! it took me a few minutes to figure out the connections for the actions but it worked amazingly! thankyou so much!
Quote this message in a reply
Member
Posts: 43
Joined: 2009.04
Post: #8
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.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #9
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. Smile
Quote this message in a reply
Member
Posts: 43
Joined: 2009.04
Post: #10
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.
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2009.03
Post: #11
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!
Quote this message in a reply
Member
Posts: 43
Joined: 2009.04
Post: #12
No problemSmile can't wait to see your finished product
Quote this message in a reply
Post Reply 

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