ios - Manage position of a moving object -
i'm making first ios app, have problem... moving objects come top of screen bottom. goal of game kill moving objects (which have random position.y) before come out of screen. if object come out, lose 1 of 3 lives. that:
if(movingobject.position.y < 0) _lives--;
but when launch app, , object come out of screen, lose 3 lives...
what lose maximum 1 life moving object?
here code create new movingobject
double curtime = cacurrentmediatime(); if (curtime > _nextmovingobjectspawn) { float randsecs = [self randomvaluebetween:3 andvalue:5]; _nextmovingobjectspawn = randsecs + curtime; float randx = [self randomvaluebetween:25 andvalue:winsize.width/2-20]; float randduration = [self randomvaluebetween:4 andvalue:6]; ccsprite *movingobject = [_movingobjects objectatindex:_nextmovingobject]; _nextmovingobject++; if (_nextmovingobject >= _movingobjects.count) _nextmovingobject = 0; [movingobject stopallactions]; movingobject.position = ccp(randx, winsize.height+movingobject.contentsize.height/2); movingobject.visible = yes; [movingobject runaction:[ccsequence actions: [ccmoveby actionwithduration:randduration position:ccp(0, -winsize.height-movingobject.contentsize.height)], [cccallfuncn actionwithtarget:self selector:@selector(setinvisible:)], nil]]; }
thank you! :)
if objects move top bottom player should lose life when 1 of them reaches bottom of screen. lose lives because check condition many times. lose 1 life per object, should remove , stop checking if position below lower edge of screen.
Comments
Post a Comment