Smoother tile map scrolling?
BlitzMax Forums/BlitzMax Programming/Smoother tile map scrolling?
| ||
Here's a problem I could never figure out. Consider this: (I know Blitz doesn't need the vars after Next, just there for clarity) ' tiles[1000] = an image array of tiles, 32x32 ' mainmap[1024,1024] = map array containing numbers pointing to the tiles in tiles[1000] ' so maybe 1-5 is grasses, 6-10 is grounds, 11-15 is water, ect. ' These next two, when incremented first pass by 32, will become 0,0 upper left of screen ' XV and YV mean "XVideo location on screen", "YVideo location on screen" ' (YV is incremented after each X row, so it starts right at 0) XV = -32 YV = 0 ' Main loop will be drawing a 15x15 section of the mainmap[] ' You're location in the mainmap[] is "master" X and Y, or MX and MY ' So we can easily draw left to right, top to bottom: For Y1 = MY To MY + 14 For X1 = MX To MX + 14 XV = XV + 32 G = mainmap[X1,Y1] DrawImage tiles[G],XV,YV Next X1 XV = -32 ' reset to left for next pass YV = YV + 32 ' inc to go down to next row Next Y1 This works well enough, sort of like Ultima 6. The trouble is it jumps 32 pixels at a time. How can it be made to move, say, 8 pixels at a time for a smoother scroll? A good example game is Eschalon, where he does move a whole tile, but he gets there in smaller increments - not jumps. How? |
| ||
This board must be magical! Every time I post something here, I figure it out like and hour later! I did it!!! All I had to do was shift the XV and YV values based on a master value, xmscroll and ymscroll. xmscroll and ymscroll control the start point of the grid draw. Shifting them a couple times, going to the draw routine after each, then resetting to begin plus incrementing the MX var at that point worked! I can scroll it as fine as I want and its still going fast. Neat thing is my main project is actually 2:1 diamond tiles and its working fine! |