B2D and Scroll Routines

BlitzPlus Forums/BlitzPlus Programming/B2D and Scroll Routines

PaulJG(Posted 2004) [#1]
I've written a little routine that scrolls a map in all directions.

Screen res is at 800 x 600, with my tiles being 64x64 pixels.

I've allowed an overlap of a tile in all directions, so its blitting 12 across and 10 down

To counter for the scroll, I've got an offset that moves the blit of the tiles over - till its more than 64 pixels, where I can just increase the map value and put the offset back to 0

Works well, but I cant seem to work out a method to get the tile at the screen coords.

At the mo I've got this:

Function get_tile(xtemp,ytemp)
tilex=xtemp/64+(mapx)
tiley=ytemp/64+(mapy)
tilenum=maze(tilex,tiley)
Return
End Function

But its wrong.. :( (also doesnt allow for the offset - xoff,yoff)

Cant seem to work it out !

Also.. I want to have a HUD over the scrolling area, is it best to blit the map, then the HUD over it - or copy the map into a blank space on the HUD.


EOF(Posted 2004) [#2]
The funtion returns nothing as it is.
Try:
Function get_tile(xtemp,ytemp) 
 tilex=xtemp/64+(mapx) 
 tiley=ytemp/64+(mapy) 
 Return maze(tilex,tiley) 
End Function



PaulJG(Posted 2004) [#3]
Sorry - should have said that 'tilex','tiley' and 'tilenum' are all global vars anyway.


turtle1776(Posted 2004) [#4]
This simple demo should help with the math portion of a 2D pixel-perfect scrolling map (ignore the clunky tiles).

http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=turtle177603142002002034&comments=no


skidracer(Posted 2004) [#5]
if mapx,mapy is the map location in pixels being drawn at top left of screen the tile the mouse is pointing to will be:

(mousex+mapx)/64,(mousey+mapy)/64