I just finished the first tutorial on the AppGameKit website and wanted to place a menu sprite on top of the parallax background. The problem I have is that the menu sprite slowly moves down with the background.
I think the problem is the SetViewOffset, but I don't how I can solve this problem
Main Loop:
#include "menu.agc"
#include "background.agc"
Type SystemType
iScreen_W as integer
iScreen_H as integer
Global System as SystemType
System.iScreen_W = 720
System.iScreen_H = 1280
SetVirtualResolution(System.iScreen_W,System.iScreen_H)
do
menu()
Gosub background_sub
sync()
loop
end
Parallax background code:
background_sub:
dim parallaxArray[150]
for i=1 to 150
spr = createSprite(0)
d = random(1,150)
SetSpriteDepth(spr, d)
SetSpriteSize(spr, 3.0-(d/100.0),-1)
SetSpritePositionByOffset(spr,random(0,System.iScreen_W),random(0,System.iScreen_H))
parallaxArray[i] = spr
next
do
vx# = GetViewOffsetX()
vy# = GetViewOffsetY()
for i = 1 to 150
spr = parallaxArray[i]
d# = getSpriteDepth(spr)
Xoff# = -(d#-System.iScreen_W)*0.01*vx#
yoff# = -(d#-System.iScreen_H)*0.01*vy#
x# = getSpriteXByOffset(spr)
y# = getSpriteYByOffset(spr)
setSpritePositionByOffset(spr, x#, y#)
SetSpriteOffset(spr,Xoff#,Yoff#)
wx# = GetSpriteX(spr)
wy# = GetSpriteY(spr)
sx# = WorldToScreenX(wx#)
sy# = WorldToScreenY(wy#)
if sy#>System.iScreen_H then SetSpritePosition(spr, random(0 ,System.iScreen_W), wy#-System.iScreen_H)
next
viewX# = GetViewOffsetX()
viewY# = GetViewOffsetY()
SetViewOffset(viewX#, viewY# -0.3)
sync()
loop
return
Menu code:
function menu()
global menu_start
menu_start = CreateSprite(0)
SetSpriteSize(menu_start, 300, 200)
SetSpriteOffset(menu_start, 300/2,200/2)
SetSpritePositionByOffset (menu_start, System.iScreen_W/2, System.iScreen_H/2)
endfunction