Issue with sprite re-position at update

Monkey Forums/Monkey Programming/Issue with sprite re-position at update

Raul(Posted 2014) [#1]
I have this issue and I really cannot understand where could be the problem.

a small class for tile:
Class cTrack
	Field posX:Float
	Field posY:Float	
End


LEVEL_H is a const which represents the number of tiles I want to use. Let' say is 5 for now.

	trackMid = New cTrack[LEVEL_H]
		
	For Local t:Int = 0 To LEVEL_H - 1
		trackMid[t] = New cTrack
		trackMid[t].posX = POSX_TRACK_1
		trackMid[t].posY = 1136 - (t * 120)
	Next

what I am doing here is to create a line of tiles from the bottom of the phone to the top. a tile has 120 px in height

and this is the updateTrackPositions method:
Method updateTracksPosition(pSpeed:Float)
	For Local t:Int = 0 To LEVEL_H - 1	
		trackMid[t].posY = trackMid[t].posY + pSpeed

		If trackMid[t].posY >= 1136			
			If t = 0
				trackMid[t].posY = trackMid[LEVEL_H - 1].posY - 120					
			Else
				trackMid[t].posY = trackMid[t - 1].posY - 120
			EndIf				
		EndIf
		
	Next
End

my logic was something like:
- if a tile is outside screen, then move it after the precedent tile ( -120 px) which always be at the top;
- if the tile which is outside screen is tile = 0 then move it before the last one from the array (otherwise would try to go to tile =-1)

in case you are wondering pSpeed value is the tmpSpeed from this:
Local tmpSpeed:Float = cDeltaTimer.gDeltaFactor * cGlobals.playerSpeed


renderTracks is simple:
	For Local t:Int = 0 To LEVEL_H - 1									
		DrawImage(imgTrack[0], trackMid[t].posX, trackMid[t].posY)			
	Next


PROBLEM:
Every time trackMid[0] is positioned there are some pixels offset. this is happening only with this tile. Doesnt matter what is LEVEL_H, the first tile will always be offset. The others are correctly rendered..

Here is a picture:



Raul(Posted 2014) [#2]
Well, fixed :))
While posting this here I tried to explain the issue to a friend of mine and than I realize where is my mistake.

This is how the updateTracks function should be:

		For Local t:Int = 0 To LEVEL_H - 1		
			trackMid[t].posY = trackMid[t].posY + pSpeed					
		Next
		
		For Local t:Int = 0 To LEVEL_H - 1
			If trackMid[t].posY >= 1136
				If t = 0
					trackMid[t].posY = trackMid[LEVEL_H - 1].posY - 120
					
				Else
					trackMid[t].posY = trackMid[t - 1].posY - 120
				EndIf
			EndIf
		Next