ios - How do I make this little twitching go away? -


so have update method in spritekit game project, in according leaders following direction position of other following characters decided:

-(void) update {  if (_followingenabled == yes || _isleader == yes) {  switch (currentdirection) {     case up:         self.position = cgpointmake(self.position.x, self.position.y + speed);         // making line of characters         if (self.position.x < _idealx && _isleader == no) {             self.position = cgpointmake(self.position.x + 1, self.position.y);         } else if (self.position.x > _idealx && _isleader == no) {             self.position = cgpointmake(self.position.x - 1, self.position.y);         }         break;     case down:         self.position = cgpointmake(self.position.x, self.position.y - speed);         // making line of characters         if (self.position.x < _idealx && _isleader == no) {             self.position = cgpointmake(self.position.x + 1, self.position.y);         } else if (self.position.x > _idealx && _isleader == no) {             self.position = cgpointmake(self.position.x - 1, self.position.y);         }         break;     case left:         self.position = cgpointmake(self.position.x - speed, self.position.y);         // making line of characters         if (self.position.y < _idealy && _isleader == no) {             self.position = cgpointmake(self.position.x, self.position.y + 1);         } else if (self.position.y < _idealy && _isleader == no) {             self.position = cgpointmake(self.position.x, self.position.y - 1);         }         break;     case right:         self.position = cgpointmake(self.position.x + speed, self.position.y);         // making line of characters         if (self.position.y < _idealy && _isleader == no) {             self.position = cgpointmake(self.position.x, self.position.y + 1);         } else if (self.position.y < _idealy && _isleader == no) {             self.position = cgpointmake(self.position.x, self.position.y - 1);         }         break;     case nodirection:         // in case want nodirection         break;     default:         break; } // switch (currentdirection) {  } // if (_followingenabled == yes && _isleader == yes) {  } 

_idealx , _idealy integers passed leader's position (i did set them properties..) , position of other characters following him float (correct me if i'm wrong)

my theory:

therefore, when add or subtract 1, position of characters(float) never equal _idealx / _idealy(int) , statements run on , over, causes little "twitching" or "shaking" on y/x axis (adding , subtracting 1).

so understand , visualise better, made screenshot of how looks (the 2 characters behind him(leader) twitch when moving..):

enter image description here

how fix followers don't "twitch" or "shake" behind leader???

i don't remember exact calculations anymore general method try , sure things aligned pixel grid display.

x = floorf(x+0.5) 

you need actual position , drawing position since if use floored values things won't work intended @ low speeds.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -