Hi Rudders, a few issues with your coding. I couldn't work out the problem, looks like a bug so I've added the solution I would use.
1-You are using a goto in the loop that feeds back outside the loop. This can cause memory issues as you are effectively creating a new loop inside the existing one each time you reset your game I would suggest you just create a separate sub-routine for resetting the position of your sprites when the button is pressed.
2-You are using the same sprite numbers as image numbers IE.createSprite(floorline,floorline) This is very confusing and also can cause other issues. It's better to either manually enforce a numbering system or let AppGameKit tell you what numbers it is going to use IE.floorline = createSprite(floorImage)
Try the code attached and read through my changes:
SetDisplayAspect( 4.0/3.0 ) rem Landscape App
SetVirtualResolution(1024, 768)
SetOrientationAllowed(0, 0, 1, 1)
REM - LOAD IMAGES
bg1 = LoadImage("background1.png")
bg2 = LoadImage("background2.png")
bg3 = LoadImage("background3.png")
bg4 = LoadImage("background4.png")
floorImage = Loadimage("floorline.png") REM RENAMED THIS IMAGE
rock = LoadImage("bolder.png")
block = LoadImage("block1anim.png")
REM CREATED A NEW SUBROUTINE FOR RESETTING THE GAME
gosub reset:
REM ********* MAIN PROGRAM LOOP ***************
do
REM - CHECK FOR RESET
If GetVirtualButtonPressed(1) = 1
DeleteSprite(bg1)
DeleteSprite(bg2)
DeleteSprite(bg3)
DeleteSprite(bg4)
DeleteSprite(floorline)
DeleteSprite(bolder)
DeleteVirtualButton(1)
For a = 200 to 320
DeleteSprite(a)
Next a
gosub reset:
Endif
REM - PARALLAX SCROLL SCREEN
If getrawkeystate(37) = 1
If GetViewOffsetX() > 3
SetViewOffset(GetViewOffSetX() - 4,0)
bg1x# = bg1x# - 3
bg2x# = bg2x# - 2
bg3x# = bg3x# - 1
SetSpritePosition(bg1,bg1x#, bg1y#)
SetSpritePosition(bg2,bg2x#, bg2y#)
SetSpritePosition(bg3,bg3x#, bg3y#)
Endif
Endif
If getrawkeystate(39) = 1
If GetViewOffsetX() < 512
SetViewOffset(GetViewOffSetX() + 4,0)
bg1x# = bg1x# + 3
bg2x# = bg2x# + 2
bg3x# = bg3x# + 1
SetSpritePosition(bg1,bg1x#, bg1y#)
SetSpritePosition(bg2,bg2x#, bg2y#)
SetSpritePosition(bg3,bg3x#, bg3y#)
Endif
Endif
REM - FIRE BOLDER
If GetPointerPressed() = 1 AND fire = 0
Xdir# = GetPointerX() * Xpower
If Xdir# > Xmax# THEN Xdir# = Xmax#
Ypoint = GetPointerY()
Ydir# = (660 - Ypoint) * Ypower
If Ydir# < Ymax# THEN Ydir# = Ymax#
rem fire = 1
SetSpritePhysicsImpulse(bolder,GetSpriteXByOffset(bolder),GetSpriteYByOffset(bolder)-2,Xdir#,Ydir#)
Endif
REM - AUTO SCROLL SCREEN
If GetSpriteX(bolder)>516 AND GetSpriteX(bolder)< 1024
SetViewOffSet(GetSpriteX(bolder) - 516,0)
V# = GetViewOffSetX()
SetSpritePosition(bg1,(V#*0.75), bg1y#)
SetSpritePosition(bg2,(V#*0.50), bg2y#)
SetSpritePosition(bg3,(V#*0.25), bg3y#)
Endif
REM - BOLDER COLLISION TEST
i = getFirstContact()
while i>0
spr1 = GetContactSpriteID1( )
spr2 = GetContactSpriteID2( )
if spr1=bolder
Print("Boulder is touching sprite "+str(spr2))
else
if spr2=bolder
Print("Boulder is touching sprite "+str(spr1))
endif
endif
i = getNextContact()
endwhile
Print("Xdir = "+str(Xdir#)+" Ydir = "+str(Ydir#))
Print("Bolder Velocity = "+str(GetSpritePhysicsVelocityX(bolder)))
Sync()
loop
reset:
REM - INITIATE VARIABLE
bg1x# = 0
bg2x# = 0
bg3x# = 0
bg4x# = 0
bg1y# = 0
bg2y# = 180
bg3y# = 300
bg4y# = 373
fire = 0
Xdir# = 0
ydir# = 0
Xpower = 150
Ypower = -110
Xmax# = 38000
Ymax# = -45000
block1 = 199
blockmass = 30
boldermass = 200
towerx = 1200
towery = 700
global bolder as integer
SetViewOffSet(0,0)
V# = 0
REM - VIRTUAL BUTTONS
AddVirtualButton(1, 40, 720, 40 )
SetVirtualButtonText(1, "RESET" )
REM - CREATE SPRITES
CreateSprite(bg1,bg1)
SetSpritePosition(bg1,bg1x#,bg1y#)
CreateSprite(bg2,bg2)
SetSpritePosition(bg2,bg2x#,bg2y#)
CreateSprite(bg3,bg3)
SetSpritePosition(bg3,bg3x#,bg3y#)
CreateSprite(bg4,bg4)
SetSpritePosition(bg4,bg4x#,bg4y#)
floorline=CreateSprite(floorImage) REM EDITED HOW THE SPRITE NUMBER IS CREATED
SetSpriteShape(floorline,2)
SetSpriteVisible(floorline,0)
SetSpritePhysicsOn(floorline,3)
SetSpritePosition(floorline,0,700)
bolder=CreateSprite(rock) REM EDITED HOW THE SPRITE NUMBER IS CREATED
SetSpriteShape(bolder,3)
SetSpritePhysicsOn(bolder,2)
SetSpritePosition(bolder,80,664)
SetSpritePhysicsFriction(bolder,0.9)
SetSpritePhysicsMass(bolder, boldermass)
REM - CREATE TOWER
For col = 1 to 20
For row = 1 to 6
block1 = block1 + 1
block1=CreateSprite(block)
SetSpriteAnimation(block1,32,19,10)
SetSpritePosition(block1, towerx + (row * 32), towery + (col * -19))
SetSpritePhysicsOn(block1,2)
SetSpritePhysicsFriction(block1, 1 )
SetSpritePhysicsMass(block1, blockmass)
Next row
Next col
return