looked at different codes and trying to understand tile maps, 2d arrays and matricies, but having a little trouble. I managed to get this to load but "error null object access" keeps happening. for some reason i have to put field bg on both calsses or i get error bg not declared. pls help have to understan tile maps. should i have went with screen width divide by tile size idk
also can someone point me to scrolling single image background
heres the code.
Import mojo
Class Mygame Extends App
global level:Level
Field width:Int = 320
Field hieght:Int =240
Global bg:Image
Method OnCreate()
SetUpdateRate(60)
level= New Level()
bg = LoadImage("level.png",128,128,8,Image.MidHandle)
End
Method OnUpdate()
End
Method OnRender()
Cls(0,0,0)
level.Draw()
End
End
Class Level
Field tileH:Int =128
Field tileW:Int =128
field bg:Image
Field cols:Int = 5
Field rows:Int = 3
Field map:Int [][]= [[1,1,1,1,1],
[2,2,2,2,2],
[3,6,2,5,4]]
Method Draw:Void()
For Local i:Int = 0 until rows
For Local j:Int = 0 until cols
If map[i][j] =1 Then DrawImage (bg,i*tileW,j*tileH,1)
'Select map[i][j]
'Case 1
' DrawImage (bg,i*tileW,j*tileH,1)
' End
End
End
End
End
Function Main:int()
New Mygame
End
|