oK what we have here is a space invader type game. The 8 sprites bounce from wall to wall like the classic game does. If it hits the left wall, the global variable is set to RIGHT and vice versa for the other wall.Code:if (R5Direction='RIGHT')then begin X:=x+Speed1*dx; end; if (R5Direction='LEFT')then begin X:=X-Speed1*dx; end; if (X>=GameAreaX2-Image.width)then //hits right wall begin R5Direction:='LEFT'; //sets all 8 sprites to go left end; if (X<=GameAreaX1)then // hits left wall begin R5Direction:='RIGHT'; end;
Problem. When first sprite hits left wall, instead of just turning right at same time as the other sprites, it jerks and then goes out of sync with the other sprites. After a while the gap between sprite 1 and sprite 2 becomes huge. The faster the sprite moves the larger the gap becomes each time the wall is hit.
The code dictates that all sprites should move left and right at the same time, but srpite 1 is being treated differently to sprite 2-8
Sprite 8 hits the Right wall but everything stays in sync. It only happens with sprite 1 on the left wall if the code is exactly as above.
Bookmarks