2D Array within a Type
BlitzMax Forums/BlitzMax Beginners Area/2D Array within a Type
| ||
How do you create a 2D Array within a type, since you do not dimension the array as in BlitzPlus Type Grid Field GridNumber:Int Field GridSector:Int Field GridImage:TImage End Type The GridImage field will hold a graphic image used with a for loop to draw the grid. This should be done without the use of TLists as I will need to access an element of the GridNumber without looping through the list. |
| ||
Using a normal 2D array:Type TGrid Field coords:Int[10,10] End Type Local myGrid:TGrid = New TGrid For Local X = 0 To 9 For Local Y = 0 To 9 myGrid.coords[X,Y] = X+Y Next Next For Local A = 0 To 9 For Local B = 0 To 9 Print myGrid.coords[A,B] Next Next Multidimensional arrays cannot be resized. See the BlitzWiki for more info. |
| ||
Can the image (that is the reference to the image) be loaded into the type field (GridImage) that is a 2D array so that the grid can be drawn using For x = 0 to 9 For y = 0 to 9 Print myGrid.GridImage(x, y), x*32, y*32 next next |
| ||
it *could* but unless they're all unique images, you'd be better having an array of ints that refer to the images. i.e.: Global images:TImage[5] for Local a = 0 to 4 images[a]:TImage = LoadImage("tile"+a+".png") 'load tile0.png, tile1.png, tile2.png etc Next Type TGrid Field coords:Int[10,10] End Type Local myGrid:TGrid = New TGrid myGrid[0,1] = 2 'will use tile2.png For Local X = 0 To 9 For Local Y = 0 To 9 DrawImage images[myGrid.coords[X,Y]], X*32, y*32 Next Next |
| ||
Thanks Perturbatio, your help in this matter is greatly appreciated. |
| ||
Thanks Perturbatio, your help in this matter is greatly appreciated. np :) |