How to side scroll?

BlitzMax Forums/BlitzMax Beginners Area/How to side scroll?

Jebbs(Posted 2008) [#1]
Ok. I'm making a game in blitzmax that is similar to super mario and donkey kong country. One of the problems I'm having with it is that I do not understand how to make the screen scroll left and right when the player is within one forth of the way from either side of the screen (that way there is some room where the character can move without the screen moving all the time).

I also would like someone to explain "tile mapping" because maybe that would be easier than plotting images everywhere.

I would really appreciate anyone's help with this. Thanks!


MGE(Posted 2008) [#2]
Think of a 640x480 screen divided into 32x32 tiles, gives you 20 across and 15 down. So every frame you're drawing each tile. It's slightly slower to draw every tile, every frame, but it's the way I've been doing it for years and never really had any problems.

In my MGE game engine, it has a fully functional tile engine that allows you to scroll any direction, multiple layers for parallax scrolling, etc, etc. To scroll around I just draw the tile map offset by x,y pixels. I also draw an extra row/column on the sides to compensate for the scrolled area. I only draw the section of the tile map that's visible. Sprites live inside the tile map, so if the map x,y changes the sprites automatically are updated. To keep the sprite in the middle I just subtract half the screen width/height from the sprite's position and make that the tile map top left x,y.

Here's a basic demo of the tile engine:

http://blitzmax-2d-game-engine.blogspot.com/2007_08_01_archive.html

I'm just not getting back into coding my game engine, I should have more details in the coming weeks. ;)


Czar Flavius(Posted 2008) [#3]
If you have the tiles stored in an array [x, y] and you can use maths (if you know the size of the tile, and the current screen location) to work out what range of x's and y's are visible, then you don't need to draw every tile and its contents, just those visible.

So if the screen size is 100x100 and each tile is 10x10 (easy numbers to keep it simple) and the x corner of the player's screen is at 115, then you need to draw from x = 11 to x = 22 of the array.


nino(Posted 2008) [#4]
if you want a dead easy way to have the camera follow your player do this:

SetOrigin(-(player.x-GraphicsWidth()/2),-(player.y-GraphicsHeight()/2))

Graphics(640,480)
Global player:Tplayer=New Tplayer

Type Tplayer
Field x:Float,y:Float,speed:Float=10
Method do()
	If KeyDown(KEY_UP) y:-speed
	If KeyDown(KEY_DOWN) y:+speed
	If KeyDown(KEY_LEFT) x:-speed
	If KeyDown(KEY_RIGHT) x:+speed
	DrawOval(x,y,20,20)
EndMethod
EndType

Function grid()
	For Local i:Int=0 To 10
		DrawLine(0,i*50,500,i*50)
	Next
	For Local i:Int=0 To 10
		DrawLine(i*50,0,i*50,500)
	Next
EndFunction


While Not AppTerminate()
	Cls
	SetOrigin(-(player.x-GraphicsWidth()/2),-(player.y-GraphicsHeight()/2))
	grid()
	player.do()
	Flip
Wend