Hello,i have a big problem. I have a function which creates random map from hexagons, but when i generate a map from like 400 hexagons and i move it with touch listener, then the transition is laggy.
And my question is- can i create one object(image) that will be the map and the image will be created from random generated hexagons.
So i will have f.e. 400 hexagons and i want to create an image from these-there are like 10 different colors used + borders.
Or is there a better solution?
Thank you a lot.
you could use newTexture to pre-render to a canvas, tho watch dimensions and memory issues if the full map is large.
Yes. Your best bet would be to use one image that takes its source from a spriteSheet. Stamp that one image all over the place based on your map data. Then you have 1 image populated all over an imageGroup you can move around as your map.
I do something like this
local yourSheetHexes= graphics.newImageSheet( "tm/dat/WallTilesMaster.png", options:getSheet() ) local drawY = 0 local drawX = 0 local OffsetX=32 local OffsetY=64 -- The viewMap is a table of tables. It contains a map (viewMap.mapData[of 32x32 tiles] I pull from Tiled data and hook some other variables to it. -- its not hex, but you get the idea. for row=1, (viewMap.mapheight) do for column=1, (viewMap.mapWidth) do num=num+1 drawX = drawX+ 32 --viewMap.tileWidth tileNumber = viewMap.mapData [((viewMap.mapWidth\*(row-1))+ (column) )] currentTile= display.newImage (sheetWalls ,viewMap.mapData[num] ) currentTile.anchorX = 0 ; currentTile.anchorY = 0 currentTile.x = currentTile.x + (column-1) \* 32 -- viewMap.tileWidth currentTile.y = currentTile.y + drawY currentTile.x = currentTile.x+OffsetX currentTile.y = currentTile.y+OffsetY myMapGroup:insert(currentTile) end end
Then I just move around myMapGroup in the touch event listener. I don’t set event listeners to each tile. I have another invisible tilelayer that has code/collision… I find out things like where the player pressed just using the location of the image, the offset, and the raw data it came from. Takes some math, but moves super fast.
you could use newTexture to pre-render to a canvas, tho watch dimensions and memory issues if the full map is large.
Yes. Your best bet would be to use one image that takes its source from a spriteSheet. Stamp that one image all over the place based on your map data. Then you have 1 image populated all over an imageGroup you can move around as your map.
I do something like this
local yourSheetHexes= graphics.newImageSheet( "tm/dat/WallTilesMaster.png", options:getSheet() ) local drawY = 0 local drawX = 0 local OffsetX=32 local OffsetY=64 -- The viewMap is a table of tables. It contains a map (viewMap.mapData[of 32x32 tiles] I pull from Tiled data and hook some other variables to it. -- its not hex, but you get the idea. for row=1, (viewMap.mapheight) do for column=1, (viewMap.mapWidth) do num=num+1 drawX = drawX+ 32 --viewMap.tileWidth tileNumber = viewMap.mapData [((viewMap.mapWidth\*(row-1))+ (column) )] currentTile= display.newImage (sheetWalls ,viewMap.mapData[num] ) currentTile.anchorX = 0 ; currentTile.anchorY = 0 currentTile.x = currentTile.x + (column-1) \* 32 -- viewMap.tileWidth currentTile.y = currentTile.y + drawY currentTile.x = currentTile.x+OffsetX currentTile.y = currentTile.y+OffsetY myMapGroup:insert(currentTile) end end
Then I just move around myMapGroup in the touch event listener. I don’t set event listeners to each tile. I have another invisible tilelayer that has code/collision… I find out things like where the player pressed just using the location of the image, the offset, and the raw data it came from. Takes some math, but moves super fast.