ios - Random Positioning issue -
i trying atm doing game. got problems randompositioning blocks. code, blocks keep spawning @ same lane fast. thats not mean to. should appear mario game. code:
humanmovement = [nstimer scheduledtimerwithtimeinterval:0.03 target:self selector:@selector(humanmoving) userinfo:nil repeats:yes]; [self placeblocks]; blockmovement = [nstimer scheduledtimerwithtimeinterval:0.03 target:self selector:@selector(blockmoving) userinfo:nil repeats:yes]; } -(void)blockmoving{ startingblock.center = cgpointmake(startingblock.center.x -1, startingblock.center.y); block1.center = cgpointmake(block1.center.x -1, block1.center.y); block2.center = cgpointmake(block2.center.x -1, block2.center.y); if ( block1.center.x > 20) { [self placeblocks]; } } -(void)placeblocks{ randomblock1position = arc4random() %568; randomblock1position = randomblock1position + 140; randomblock2position = randomblock2position + 500; block1.center = cgpointmake(193 , randomblock1position); block2.center = cgpointmake(280 , randomblock2position); }
so if understood correctly blocks should respawn once reach left side. in order have change center check position :
if ( block1.center.x < 20) { [self placeblocks]; }
Comments
Post a Comment