2D Scrolling

Blitz3D Forums/Blitz3D Beginners Area/2D Scrolling

GIB3D(Posted 2008) [#1]
Hi I'm working on a map editor for my game and I need to change how the grid works. Right now it is limited to the resolution of the window. I want it to be able to scroll around to create bigger maps but I am unsure how.

There was one I looked at that included a tank demo for the map that had A* pathfinding but it's too confusing for me.

Can anyone give me some code for some simple 2D scrolling grid where you can place tiles on it and the tiles will move with the grid?


Snarkbait(Posted 2008) [#2]
you just use an offset to the screen position.

you need 2, an x offset and a y offset

then you need an x max value and a y max value

say the window is 800 x 600 but the map is 1280x1024 or suchlike, when the whole window is scrolled, you add to the offset, making sure it doesn't go over max - screenwidth

in your draw routines, do something like

DarawImage img, x + xOffset, y + yOffset,...


GIB3D(Posted 2008) [#3]
Well you see, i want to make long sidescrolling maps like in Super Mario World. I want the grid to be infinite just like if you did CreatePlane() except that's for 3D.


Snarkbait(Posted 2008) [#4]
Same idea. Just use an offset.


GIB3D(Posted 2008) [#5]
I think I might have found myself an answer

This is my image
m\map=CreateImage(32,32)

SetBuffer ImageBuffer(m\map)
For y1 = 0 To 1
	For x1 = 0 To 1
		Color 90,90,0
		Rect x1*32,y1*32,32,32,0
	Next
Next
SetBuffer BackBuffer()


and I use
TileImage m\map
to make it infinte

I have it so the x and y coords of the image are controlled with the mousex and mousey but I could change that to something else to scroll the map around. The placed tiles seem to move around with the coords so there's some possibilities here... I'll try some things out and ask for more help if I need to.

If it's an infinite grid, I guess I wouldn't have to move the actual grid itself.


GIB3D(Posted 2008) [#6]
Ok It works, thanks for your help :)
This would also help me if I ever wanted to make my 3D Side Scrolling game into 2D. Thank you sooo much! This help a lot!