ios - Why is one of my NSTimer messing up my background movement? -
i have 2 nstimer. problem countdown timer messes background positioning countdown timer stops. background moves until point background timer stops. automatically reposition background starting position, not want because seems glitchy when happens. want keep flowing smoothly countdown timer stops. if take countdown timer out, background movement works perfectly. here code:
playviewcontroller.h
#import <uikit/uikit.h> @interface playviewcontroller : uiviewcontroller { int countdownstatus; iboutlet uiimageview *background; nstimer *backgroundmovement; nstimer *gamecountdowntimer; } @property (strong, nonatomic) iboutlet uilabel *countdownlabel; - (void)backgroundmoving; - (void)gamecountdown; @end playviewcontroller.m
#import "playviewcontroller.h" @interface playviewcontroller () @end @implementation playviewcontroller - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; self.countdownlabel.text = @"3"; countdownstatus = 2; gamecountdowntimer = [nstimer scheduledtimerwithtimeinterval:1.0f target:self selector:@selector(gamecountdown) userinfo:nil repeats:yes]; backgroundmovement = [nstimer scheduledtimerwithtimeinterval:0.01f target:self selector:@selector(backgroundmoving) userinfo:nil repeats:yes]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (void)backgroundmoving { background.center = cgpointmake(background.center.x - 1, background.center.y); cgrect backgroundframe = background.frame; if(backgroundframe.origin.x < -370) { cgrect myframe = background.frame; myframe.origin.x = 0; myframe.origin.y = 0; background.frame = myframe; } } - (void)gamecountdown { if(countdownstatus == 2) self.countdownlabel.text = @"2"; else if(countdownstatus == 1) self.countdownlabel.text = @"1"; else self.countdownlabel.text = @""; countdownstatus--; } @end
Comments
Post a Comment