Tilemap Scrolling for Top-Down Shooter?

Monkey Forums/Monkey Programming/Tilemap Scrolling for Top-Down Shooter?

zoqfotpik(Posted 2013) [#1]
Is there a code sample available for tilemap scrolling in a top-down shooter where the player is always in the center of the screen and the tilemap scrolls smoothly as he moves?


Xaron(Posted 2013) [#2]
Ignition from Playniax has such an example:

http://www.playniax.com/demos/tiles/html5/demo.html


Midimaster(Posted 2013) [#3]
I would use Translate() to move the graphic origin depending on the player x and y values.

With PopMatrix() you can reset this offset to paint things which do not move:

[monkeycode]Strict
Import mojo

Class Game Extends App

Field X%=500,Y%=800
Method OnCreate%()
SetUpdateRate 60
Return 0
End

Method OnUpdate%()
If KeyHit(KEY_ESCAPE) Then Error ""
If KeyDown(KEY_A)
X=X-1
Elseif KeyDown(KEY_S)
X=X+1
Endif
Y=Y-1
Return 0
End

Method OnRender%()
Cls
PushMatrix()
Translate -X+DeviceWidth()/2,-Y+DeviceHeight()/2
For Local i%=0 To 29
For Local j%=0 To 20
DrawRect i*50,j*50,49,49
Next
Next
SetColor 255,0,0
DrawRect X,Y,39,39
PopMatrix()
Scale 3,3
DrawText "Press A or S to move",30,30
Return 0
End

End

Function Main%()
New Game
Return 0
End




[/monkeycode]


zoqfotpik(Posted 2013) [#4]
Translate is probably what I will use-- I will look into that method. I'm used to the old way of doing things where everything is offset as part of the drawrect call but this may make matters somewhat easier.