I started to code this prototype racing game and Im trying to make my tires spin. Whenever I add in the for loop to make them spin, the game lags terribly. Is there anyway to fix this? Im running an RTX 3070 so theres no way its a graphics card issue
// Project: Final
// Created: 2021-02-15
// show all errors
SetErrorMode(2)
SetVSync(1)
// set window properties
SetWindowTitle( "BIT RACER" )
SetWindowSize( 1920, 1080, 0 )
SetWindowAllowResize( 0 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1920, 1080 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
//SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
//scrolling background
SetDefaultWrapU(1)
backdropIM = LoadImage("Plains_bkgrnd.png")
backdropSP = CreateSprite(backdropIM)
SetSpriteSize(backdropSP, 1920, 1080)
//*** Load images ***
LoadImage(1, "hurracan.png")
CreateSprite(1,1)
SetSpriteSize(1,600,-1)
LoadImage(2, "rim.png")
CreateSprite(2,2)
SetSpriteSize(2,75,75)
LoadImage(3, "rim.png")
CreateSprite(3,3)
SetSpriteSize(3,75,75)
xscroll#=0
do
// obtain joystick input from either a real joystick, keyboard (w, a, s and d) or virtual joystick
x# = GetJoystickX ( ) + x#*1.0001
y# = 8*GetJoystickY ( )
// show joystick input on screen
Print ( x# )
Print ("Miles Per Hour")
// add input to sprites position
SetSpritePosition ( 1, GetSpriteX ( 1 ) + x#, GetSpriteY ( 1 ) + y# )
// ensure sprite cannot move past left of screen
if ( GetSpriteX ( 1 ) < 10 )
SetSpriteX ( 1, 10 )
endif
// ensure sprite cannot move past right of screen
if ( GetSpriteX ( 1 ) > 500 )
SetSpriteX ( 1, 500 )
endif
// ensure sprite cannot move past top of screen
if ( GetSpriteY ( 1 ) < 120 )
SetSpriteY ( 1, 120 )
endif
// ensure sprite cannot move past bottom of screen
if ( GetSpriteY ( 1 ) > 700 )
SetSpriteY ( 1, 700 )
endif
SetSpritePosition ( 2, GetSpriteX ( 1 )+93, GetSpriteY(1) +(y#+305) )
// ensure sprite cannot move past left of screen
if ( GetSpriteX ( 2 ) < 1 )
SetSpriteX ( 2, 1 )
endif
// ensure sprite cannot move past right of screen
if ( GetSpriteX ( 2 ) > 593 )
SetSpriteX ( 2, 593 )
endif
// ensure sprite cannot move past top of screen
if ( GetSpriteY ( 2 ) < 120 )
SetSpriteY ( 2, 120 )
endif
// ensure sprite cannot move past bottom of screen
if ( GetSpriteY ( 2 ) > 1006 )
SetSpriteY ( 2, 1006 )
endif
SetSpritePosition ( 3, GetSpriteX ( 1 )+370, GetSpriteY(1) +(y#+309) )
// ensure sprite cannot move past left of screen
if ( GetSpriteX ( 3 ) < 1 )
SetSpriteX ( 3, 1 )
endif
// ensure sprite cannot move past right of screen
if ( GetSpriteX ( 3 ) > 893 )
SetSpriteX ( 3, 893 )
endif
// ensure sprite cannot move past top of screen
if ( GetSpriteY ( 3 ) < 120 )
SetSpriteY ( 3, 120 )
endif
// ensure sprite cannot move past bottom of screen
if ( GetSpriteY ( 3 ) > 1006 )
SetSpriteY ( 3, 1006 )
endif
SetSpriteUVOffset(backdropSP, x#*2, 0)
// update contents of screen
for i=1 to 360 step 9
SetSpriteAngle(3,i)
SetSpriteAngle(2,i)
sync()
next i
Sync ( )
loop