Quote: ""If my code is incorrect, if possible please give correct code for scrolling that work on mobile without lag.""
Yeah, it's doing my head in.
Others have already suggested you are doing things incorrectly. So why haven't you tried doing something else? You just keep on asking the same stuff over and over, whilst telling everyone how great your games were on those game-makers you used to use.
Personally, if it was me, Id listen to the advice given and experiment with other ways to do what you are trying to achieve. Maybe start with un-hooking your scroll speed from the fps (as currently, any glitch in fps would cause a stutter in the scrolling). Perhaps something along the lines of:
SetWindowSize( 1280, 800, 0 )
SetDisplayAspect(-1)
global player
global dim BackSpr[4]
CreatePlayer()
CreateBackground()
xscreenpos# = 0.0
xscrollspeed# = 30.0
do
xscreenpos# = xscrollspeed# * timer()
// Move View
SetViewOffset(xscreenpos#,GetViewOffsetY())
//Move Background
for a = 1 to 2
`if GetSpriteExists(BackSpr[a]) = 1
if WorldToScreenX(GetSpriteX(BackSpr[a])) <= -100
SetSpriteX(BackSpr[a],GetSpriteX(BackSpr[a])+200)
endif
`endif
next a
for b = 2 to 4
`if GetSpriteExists(BackSpr[b]) = 1
if WorldToScreenX(GetSpriteX(BackSpr[b])) <= -100
SetSpriteX(BackSpr[b],GetSpriteX(BackSpr[b])+200)
endif
`endif
next b
if GetSpriteExists(player) = 1
SetSpritePosition(player,GetViewOffsetX()+10,GetSpriteY(player))
endif
Sync()
loop
//==============================================>>Functions
Function CreatePlayer()
player = CreateSprite(0)
SetSpriteShape(player,3)
SetSpriteAnimation(player,256,256,2)
SetSpriteposition(player,10,40)
SetSpriteColor(player,255,0,0,255)
SetSpriteSize(player,10,-1)
SetSpriteDepth(player,2)
EndFunction
Function CreateBackground()
EmptyBackSpr = CreateSprite(0)
SetSpriteTransparency(EmptyBackSpr, 0)
SetSpriteVisible(EmptyBackSpr,0)
for a = 1 to 4
if GetSpriteExists(BackSpr[a]) = 0
BackSpr[a] = CloneSprite(EmptyBackSpr)
SetSpriteVisible(BackSpr[a],1)
SetSpriteSize(BackSpr[a],50,100)
SetSpriteDepth(BackSpr[a],1000)
Select a
case 1:
SetSpriteColor(BackSpr[1],0,0,255,255) //blue
SetSpritePosition(BackSpr[1],0,0)
endcase
case 2:
SetSpriteColor(BackSpr[2],0,255,0,255) //green
SetSpritePosition(BackSpr[2],50,0)
endcase
case 3:
SetSpriteColor(BackSpr[3],0,0,255,255) //blue
SetSpritePosition(BackSpr[3],100,0)
endcase
case 4:
SetSpriteColor(BackSpr[4],0,255,0,255) //green
SetSpritePosition(BackSpr[4],150,0)
endcase
EndSelect
endif
next a
EndFunction
BUT for what it's worth, I think you should go back to 3DRAD or Game-Editor Behdadsoft. The screenshots you posted of the racing game you made look amazing!
Please.