been trying to get good scrolling but using getspritex(cannon) and getspritey(cannon) with setviewoffset() aint good enough as it jumps straight to it of course, so consider i have a sprite called cannon and another called cannonball, how would i have it scroll nicely after the cannonball passes through the centre of the screen ?
here is what I have tried so far:
rem
rem AGK Application
rem
rem Landscape App
SetDisplayAspect( 1024.0 / 600.0 )
global brickcount = 0
global bricklimit= 800
global cannon=810
global cannonball = 811
global shot = 0
global y#
`setphysicsgravity(0,0)
type mybrick
xloc as integer
yloc as integer
imagenum as integer
spritenumber as integer
sizex as integer
sizey as integer
physicstype as integer
bangle as integer
sprshape as integer
endtype
global dim brick[800] as mybrick
init()
`load_level()
SetPhysicsDebugOn()
do
control()
if getspriteexists(cannonball)
xs#=getspritex(cannonball)-50
ys#=getspritey(cannonball)-50
SetViewOffset(xs#,ys#)
FixSpritetoScreen(cannonball,0)
endif
Sync()
loop
function control()
r=getvirtualbuttonpressed(1)
t=getvirtualbuttonpressed(2)
s=getvirtualbuttonpressed(3)
y#=getspriteangle(cannon)
if r = 1 and y#>0
setspriteangle(cannon,getspriteangle(cannon)-2)
sync()
endif
if t = 1
setspriteangle(cannon,getspriteangle(cannon)+2)
endif
if s = 1 and shot = 0
shot = 1
createsprite(cannonball,0)
setspritesize(cannonball,2,-1)
setspriteshape(cannonball,1)
setspriteposition(cannonball,getspritex(cannon),getspritey(cannon) )
setspritephysicson(cannonball,2)
setspritephysicsmass(cannonball,1.0)
SetSpritePhysicsCanRotate(cannonball,0)
angle#=getspriteangle(cannon)
speed#=120.5
vx#=cos(angle#)*speed#
vy#=sin(angle#)*speed#
setspritephysicsvelocity(cannonball,vx#,vy#)
endif
`if shot =1 and spritevelocityx
endfunction
function init()
setclearcolor(10,200,10)
clearscreen()
`loadimage(1,"redbrick.png")
`loadimage(2,"greenbrick.png")
`loadimage(3,"bluebrick.png")
`loadimage(4,"ball.png")
`loadimage(5,"cannon.png")
createsprite(cannon,0)
setspritesize(cannon,12,6)
setspriteposition(cannon,10,76)
addvirtualbutton(1,10,90,5)
setvirtualbuttontext(1,"Angle -")
addvirtualbutton(2,20,90,5)
setvirtualbuttontext(2,"Angle +")
addvirtualbutton(3,30,90,5)
setvirtualbuttontext(3,"SHOOT!")
endfunction
`************************************************ Load Function *********************************
function load_level()
myfile = OpenToread("Test2.dat")
`brickcount = readinteger (myfile)
for n = 1 to bricklimit
xl = readinteger (myfile)
yl = readinteger (myfile)
im = readinteger (myfile)
sn= readinteger (myfile)
sx = readinteger (myfile)
sy = readinteger (myfile)
psm = readinteger (myfile)
ba=readinteger (myfile)
sprs= readinteger (myfile)
brick[n].xloc = xl
brick[n].yloc = yl
brick[n].imagenum = im
brick[n].spritenumber = sn
brick[n].sizex = sx
brick[n].sizey = sy
brick[n].physicstype = psm
brick[n].bangle = ba
brick[n].sprshape = sprs
if brick[n].spritenumber <> 0
inc brickcount
createsprite (brickcount,brick[n].imagenum)
setspriteshape(brickcount,brick[n].sprshape)
SetSpriteGroup ( brickcount,brickgroup)
SetSpriteOffset(brickcount,getspritewidth(brickcount)/2,getspriteheight(brickcount)/2)
setspritesize(brickcount,sx,sy)
setspriteangle(brickcount,brick[n].bangle)
setspriteposition(brickcount,brick[n].xloc,brick[n].yloc)
if brick[n].physicstype >0
setSpritePhysicsOn(brickcount,brick[n].physicstype)
endif
endif
next n
closefile (myfile)
print("loaded!!")
sync()
endfunction
`************************************************************************************************
The code for what i need is in the main do-loop, most of the other functions are remmed out for the sake of not needing external media!
Hail to the king, baby!