Friday, April 5, 2013

Tiles and polygons and hash tables oh my!

I have been getting a better grasp on the mesh function in codea. A light just went off today about how this works. The quick of it is when you add a new rectangle the mesh it gets an index number. To target rectangle you need to store this reference number.

On the codea forums someone created a hash table to store the mesh and it's rectangles and functions to 
add and remove rectangles. 

Use meshNewRect(myMesh, x, y, w, h, [r]) instead of myMesh:addRect(x, y, w, h, [r]), To remove the rectangle  use meshFreeRect(myMesh, index.

For example:
map = mesh()
for x = 1 to 10, do
     for y= 1 to 10 do
          mapList[x][y] = addTile(meshNewRect(myMesh, x, y, w, h, [r], tileName,health,blocksLOS,visible)

This way you acccess the mesh throught the mapList x and y positions. modifying the rectanges position, size and texture cordinated are simple. wel as simple an any programming can be.

Next to inplement this into my game framework.

No comments:

Post a Comment