objective c - iOS: How can I make this game reset button work properly? -


i have game fireball uiimage falls screen, , user moves player object touch screen avoid them. after 8 points, playagainbutton pops up. however, playagainbutton button isn't working. doesn't execute of code in resetgame method, , resets position of character object "dustin", don't want happen. have referencing outlet attached button. how can code in resetgame work? viewcontroller code below.

 int thescore;  - (void)viewdidload {     [super viewdidload];      // additional setup after loading view, typically nib.     [self initializetimer]; }  - (ibaction)resetgame:(id)sender {  //only thing happens right dustin resets reason.     thescore = 0;      [self updatescore];      _fireball.center = cgpointmake(64, 64);     _endlabel.hidden = true;     _playagainbutton.hidden = true;      [self gamelogic:thetimer]; }  - (void)updatescore {     _score.text = [[nsstring alloc] initwithformat:@"%d",thescore]; }  - (void) initializetimer {     if(thetimer == nil)     {         thetimer = [cadisplaylink displaylinkwithtarget:self selector:@selector(gamelogic:)];     }      thetimer.frameinterval = 1;     [thetimer addtorunloop:[nsrunloop currentrunloop] formode:nsdefaultrunloopmode]; }  - (void) gamelogic:(cadisplaylink *) thetimer {     if((!cgrectintersectsrect(_fireball.frame, _dustin.frame)) && (thescore < 8)){         if(_fireball.center.y >600){             int num = arc4random() % 3;             if(num == 0){                 _fireball.center = cgpointmake(64, 64);             }             else if(num == 1){                 _fireball.center = cgpointmake(192, 64);             }             else if(num == 2){                 _fireball.center = cgpointmake(320, 64);             }              thescore = thescore + 1;             [self updatescore];             }            _fireball.center = cgpointmake(_fireball.center.x, _fireball.center.y+12);    }     else if(thescore == 8){         _fireball.center = cgpointmake(_fireball.center.x, _fireball.center.y);          _endlabel.text = @"you win!";         _endlabel.hidden = false;         _playagainbutton.hidden = false;     } }  - (void) touchesbegan:(nsset *) touches withevent:(uievent *) event {     uitouch *touch = [touches anyobject];      _firsttouch = [touch locationinview:self.view];     _lasttouch = [touch locationinview:self.view];      _dustin.center = cgpointmake(_firsttouch.x, _dustin.center.y); }  -(void) touchesended:(nsset *)touches withevent:(uievent *)event{     uitouch *touch = [touches anyobject];      _firsttouch = [touch locationinview:self.view];     _lasttouch = [touch locationinview:self.view];      _dustin.center = cgpointmake(_firsttouch.x, _dustin.center.y); }  -(void) touchesmoved:(nsset *)touches withevent:(uievent *)event{     uitouch *touch = [touches anyobject];      _firsttouch = [touch locationinview:self.view];     _lasttouch = [touch locationinview:self.view];      _dustin.center = cgpointmake(_firsttouch.x, _dustin.center.y); }  - (void)didreceivememorywarning {     [super didreceivememorywarning];      // dispose of resources can recreated. } 

your touchesbegan etc. methods not calling super , touches being captured app , cannot through button.

add call super each of these methods.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -