Quote: "I need a multi directional solution as per GameDevGuy's image to simulate an open world top down space scene"
Ah. Well tbh the technique I gave could work here too. Initially you place all 12 (or whatever number you need) of images. Then move all 12 by the same amount each frame (in any direction). Check each frame to see if any of them have gone over the edge and if so, adjust the position
Here's an example (you can post directly into AGK)
main.agc
SetWindowTitle( "Scrololol" )
SetWindowSize( 960,640, 0 )
// set display properties
SetVirtualResolution( 150,100 ) // 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
bg as integer[4,3]
for x=0 to 3
for y=0 to 2
bg[x,y]=CreateSprite(0)
SetSpriteSize(bg[x,y],50,50)
SetSpritePosition(bg[x,y],x*50,y*50)
SetSpriteColor(bg[x,y],random(0,255),random(0,255),random(0,255),255)
next
next
ox as float //oldX
oy as float
mx as float //moveX
my as float
cx as float //currentX
cy as float
nx as float //newX
ny as float
do
for x=0 to 3
for y=0 to 2
cx=GetSpriteX(bg[x,y])
cy=GetSpriteY(bg[x,y])
nx=cx
ny=cy
if GetPointerState()
mx=ox-GetPointerX()
my=oy-GetPointerY()
nx=cx+mx
ny=cy+my
if nx<-50 then nx=nx+200
if nx>150 then nx=nx-200
if ny<-50 then ny=ny+150
if ny>100 then ny=ny-150
endif
SetSpritePosition(bg[x,y],nx,ny)
next
next
//get the X/Y position for the next frame
ox=GetPointerX()
oy=GetPointerY()
Sync()
loop
Of course, you normally want to move the viewport around with SetViewPosition. I think my code would work exactly the same way for that actually. You would just skip all the sprite moving code, and check if a sprite goes off the edge of the screen
relative to the viewport position. It should work automatically...
Just a sec I'm gonna try it
Edit: Yep works fine
main.agc
SetWindowTitle( "Scrololol" )
SetWindowSize( 960,640, 0 )
// set display properties
SetVirtualResolution( 150,100 ) // 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
bg as integer[4,3]
for x=0 to 3
for y=0 to 2
bg[x,y]=CreateSprite(0)
SetSpriteSize(bg[x,y],50,50)
SetSpritePosition(bg[x,y],x*50,y*50)
SetSpriteColor(bg[x,y],random(0,255),random(0,255),random(0,255),255)
next
next
ox as float //oldX
oy as float
mx as float //moveX
my as float
cx as float //currentX
cy as float
nx as float //newX
ny as float
do
print("Click and Drag")
if GetPointerState()
mx=GetPointerX()-ox
my=GetPointerY()-oy
SetViewOffset(GetViewOffsetX()+mx,GetViewOffsetY()+my)
endif
for x=0 to 3
for y=0 to 2
nx=GetSpriteX(bg[x,y])
ny=GetSpriteY(bg[x,y])
if nx<GetViewOffsetX()-50 then nx=nx+200
if nx>GetViewOffsetX()+150 then nx=nx-200
if ny<GetViewOffsetY()-50 then ny=ny+150
if ny>GetViewOffsetY()+100 then ny=ny-150
SetSpritePosition(bg[x,y],nx,ny)
next
next
//get the X/Y position for the next frame
ox=GetPointerX()
oy=GetPointerY()
Sync()
loop