stationary objects when dynamically scrolling

BlitzPlus Forums/BlitzPlus Beginners Area/stationary objects when dynamically scrolling

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I apolagize at the moment I've been developing in Dark Basic Pro (I like the community here better) but you'll get the idea. From your post I guess I could use my constants GAMEWORLDWIDTH and GAMEWORLDHEIGHT to figure out where I am

here is what I am doing I got alot of it from a dark basic pro game development book
this is a bit long

say I have a bitmap composed of 10 different ground tiles

then I have a data file that is like
data 1,5,6,7,8
data 1,34,7,8 blah blah blah

then I load all this stuff into my array (perhaps a solution to your post :)

` load the tile images
load bitmap "groundtiles.bmp", IMG_TILES
`create the scroll buffer surface in memory, slightly bigger than the screen
create bitmap IMG_SCROLLBUFFER, SCROLLBUFFERWIDTH, SCROLLBUFFERHEIGHT
`load the map data into the array
for y = 0 to MAPHEIGHT-1
for x = 0 to MAPWIDTH-1
read MAPDATA(x,y)
next x
next y

in my main loop I have two methods I keep calling
update the scrolling view
UpdateScrollPosition()
`draw tiles onto the scroll buffer
DrawTileMap()


here is a piece of the update scroll position

function UpdateScrollPosition()
`scroll based on mouse input
if hunter.x < 200 and ScrollX <> 0
hunter.x = 199
dec ScrollX, hunter.speed - 2
hunter.frame = getframe(hunter)
hunter.inactive_timer = 0
endif
if hunter.x > 400 and ScrollX <> GAMEWORLDWIDTH - WINDOWWIDTH
hunter.x = 401
inc ScrollX, hunter.speed - 2
hunter.frame = getframe(hunter)
hunter.inactive_timer = 0
endif

and a couple more if then statements for the y position of the hunter then I do then I do

`update horizontal scrolling position and speed
if ScrollX < 0
ScrollX = 0
else
if ScrollX > GAMEWORLDWIDTH - WINDOWWIDTH
ScrollX = GAMEWORLDWIDTH - WINDOWWIDTH
endif
endif

`update vertical scrolling position and speed
if ScrollY < 0
ScrollY = 0
else
if (ScrollY > GAMEWORLDHEIGHT - WINDOWHEIGHT-1)
ScrollY = GAMEWORLDHEIGHT - WINDOWHEIGHT-1
endif
endif

here is the draw tile map function
`*************************Draw Tile Map*****************************************************
`This function fills the tilebuffer with tiles representing
`the current scroll display based on scrollx/scrolly.
function DrawTileMap()
`calculate starting tile position
tilex = int(ScrollX / TILEWIDTH)
tiley = int(ScrollY / TILEHEIGHT)

columns = int(WINDOWWIDTH / TILEWIDTH)
rows = int(WINDOWHEIGHT / TILEHEIGHT)

`draw tiles onto the scroll buffer surface
for y = 0 to rows
for x = 0 to columns
`retrieve the tile number from this position
tilenum = MAPDATA(tilex+x, tiley+y)

`draw the tile onto the scroll buffer
DrawTile(IMG_TILES,tilenum,TILEWIDTH,TILEHEIGHT,16,IMG_SCROLLBUFFER,x*TILEWIDTH,y*TILEHEIGHT)

next x
next y

`draws the portion of the scroll buffer onto the back buffer
`according to the current "partial tile" scroll position.
left = ScrollX MOD TILEWIDTH
top = ScrollY MOD TILEHEIGHT

`set dimensions of the source image as a rectangle
right = left + WINDOWWIDTH
bottom = top + WINDOWHEIGHT

`draw the partial tile scroll window onto the back buffer
copy bitmap IMG_SCROLLBUFFER, left, top, right, bottom, 0, 0, 0, WINDOWWIDTH, WINDOWHEIGHT
endfunction

here is the draw tile method that draw tile map calls it just draws the tile to the screen

`This function does the real work of drawing a single tile from the source image
`onto the tile scroll buffer. Parameters provide much flexibility.
function DrawTile(source as integer,tile as integer,width as integer,height as integer,columns as integer,dest as integer,destx as integer,desty as integer)
`describe the source image
left = (tile MOD columns) * width
top = (tile / columns) * height
right = left + width
bottom = top + height

`draw the tile
copy bitmap source, left, top, right, bottom, dest, destx, desty, destx+width, desty+height
endfunction