ok, first of all here's my code so far it might be a bit messy because i was testing around:sphyrth wrote: ↑Mon Jul 29, 2019 11:31 amIt's been awhile since I last checked up on this, so I would ask you to show the whole code. As I remember it, the code I gave you was a twisted mess... because I have to look all over the functions as to what the code was doing in order... specifically:

1. Are the tilequads being added first? or are we defining the map first?

2. If we define the map first, doesn't that mean we have no tilequad definitions (rocks, trees, ground, etc) to check up on?

3. Sincemap definitiondifferent frommap generationwhen should I define the tilequads?

Code: Select all

```
local tilesetImage
local tileSize = 32 -- size of tiles in pixels
local tileQuads = {} -- parts of the tileset used for different tiles
local tilesetSprite
local themap = {}
local map -- stores tiledata
local mapX, mapY -- view x,y in tiles. can be a fractional value like 3.25.
local mapWidth, mapHeight -- width and height in tiles
local dxx = 0
local dyy = 0
function tilequad(x, y, count)
local start = #tileQuads + 1 -- The #<tablename> (in this case, the tablename is tileQuads) counts the number of max tiles.
-- the +1 means we'll start at the number NEXT to the last tile.
-- This means we won't override anything before the table.
for i = start, start + count do
tileQuads[i] = love.graphics.newQuad(x * tileSize, y * tileSize, tileSize, tileSize, tilesetImage:getWidth(), tilesetImage:getHeight())
end
end
function setupTileset()
tilesetImage = love.graphics.newImage( "mytileset.png" )
--tilesetImage:setFilter("nearest", "linear")
--tileQuads[1] = love.graphics.newQuad(0 * tileSize, 1 * tileSize, tileSize, tileSize,
--tilesetImage:getWidth(), tilesetImage:getHeight())
tilequad(0, 2, 1) --grass
tilequad(2, 2, 1) --rocks
tilequad(2, 3, 1) --trees
tilesetBatch = love.graphics.newSpriteBatch(tilesetImage, mapWidth * mapHeight)
end
function themap:load()
setupMap()
setupTileset()
updateTilesetBatch()
themap:moveMap(-150, 0)
end
function updateTilesetBatch()
tilesetBatch:clear()
for x=0, mapWidth do
for y=0, mapHeight do
tilesetBatch:add(tileQuads[map[x][y].tile], math.floor(map[x][y].x), math.
floor(map[x][y].y))
end
end
tilesetBatch:flush()
end
-- central function for moving the map
function themap:moveMap(dx, dy)
for x = 0, mapWidth do
for y = 0, mapHeight do
map[x][y].x = map[x][y].x + dx
map[x][y].y = map[x][y].y + dy
--dxx = dxx + dx
--dyy = dyy + dy
-- Okay so I'm not "deleting" the tiles, but transferring their x and y coordinates
--X
if map[x][y].x < mapX - (tileSize / 2) then
map[x][y].x = map[x][y].x + (tileSize * mapWidth)
end
if map[x][y].x > mapX + (mapWidth * tileSize) - (tileSize / 2) then
map[x][y].x = map[x][y].x - (tileSize * mapWidth)
end
--Y
if map[x][y].y < mapY - (tileSize / 2) then
map[x][y].y = map[x][y].y + (tileSize * mapHeight)
end
if map[x][y].y > mapY + (mapHeight * tileSize) - (tileSize / 2) then
map[x][y].y = map[x][y].y - (tileSize * mapHeight)
end
end
end
updateTilesetBatch()
end
function setupMap()
-- We only need a tiny map for this example
mapWidth = 60
mapHeight = 60
--Leaving a space on the right and topsides so we know if the tiles are being "deleted"
mapX = -20
mapY = -20
map = {}
for x=0, mapWidth do
map[x] = {}
for y=0, mapHeight do
map[x][y] = { --Let's turn this into a table that stores 3 things:
tile = love.math.random(1, #tileQuads), -- tile = love.math.random(1, #tileQuads) or tile = love.math.random(#tileQuads) since the default min is "1",
x = x * tileSize,
y = y * tileSize
}
end
end
end
return themap, tilesetBatch
```

1. i think the tilequads are being added first

2. blank (i don't really know for this one sorry)

3. best bet is at the top of the code and if that doesn't work keep moving the definition below another definition

i don't know if you wanted me to actually answer them but i thought it might be helpful

edit: here's a cleaner version of my code

Code: Select all

```
local tilesetImage
local tileSize = 32 -- size of tiles in pixels
local tileQuads = {} -- parts of the tileset used for different tiles
local tilesetSprite
local themap = {}
local map -- stores tiledata
local mapX, mapY -- view x,y in tiles. can be a fractional value like 3.25.
local mapWidth, mapHeight -- width and height in tiles
local dxx = 0
local dyy = 0
function tilequad(x, y, count)
local start = #tileQuads + 1 -- The #<tablename> (in this case, the tablename is tileQuads) counts the number of max tiles.
-- the +1 means we'll start at the number NEXT to the last tile.
-- This means we won't override anything before the table.
for i = start, start + count do
tileQuads[i] = love.graphics.newQuad(x * tileSize, y * tileSize, tileSize, tileSize, tilesetImage:getWidth(), tilesetImage:getHeight())
end
end
function setupMap()
-- We only need a tiny map for this example
mapWidth = 60
mapHeight = 60
--Leaving a space on the right and topsides so we know if the tiles are being "deleted"
mapX = -20
mapY = -20
map = {}
for x=0, mapWidth do
map[x] = {}
for y=0, mapHeight do
map[x][y] = { --Let's turn this into a table that stores 3 things:
tile = love.math.random(1, #tileQuads), -- tile = love.math.random(1, #tileQuads) or tile = love.math.random(#tileQuads) since the default min is "1",
x = x * tileSize,
y = y * tileSize
}
end
end
end
function setupTileset()
tilesetImage = love.graphics.newImage( "mytileset.png" )
--tilesetImage:setFilter("nearest", "linear")
--tileQuads[1] = love.graphics.newQuad(0 * tileSize, 1 * tileSize, tileSize, tileSize,
--tilesetImage:getWidth(), tilesetImage:getHeight())
tilequad(0, 2, 1) --grass
tilequad(2, 2, 1) --rocks
tilequad(2, 3, 1) --trees
tilesetBatch = love.graphics.newSpriteBatch(tilesetImage, mapWidth * mapHeight)
end
function updateTilesetBatch()
tilesetBatch:clear()
for x=0, mapWidth do
for y=0, mapHeight do
tilesetBatch:add(tileQuads[map[x][y].tile], math.floor(map[x][y].x), math.
floor(map[x][y].y))
end
end
tilesetBatch:flush()
end
-- central function for moving the map
function themap:moveMap(dx, dy)
for x = 0, mapWidth do
for y = 0, mapHeight do
map[x][y].x = map[x][y].x + dx
map[x][y].y = map[x][y].y + dy
--dxx = dxx + dx
--dyy = dyy + dy
-- Okay so I'm not "deleting" the tiles, but transferring their x and y coordinates
--X
if map[x][y].x < mapX - (tileSize / 2) then
map[x][y].x = map[x][y].x + (tileSize * mapWidth)
end
if map[x][y].x > mapX + (mapWidth * tileSize) - (tileSize / 2) then
map[x][y].x = map[x][y].x - (tileSize * mapWidth)
end
--Y
if map[x][y].y < mapY - (tileSize / 2) then
map[x][y].y = map[x][y].y + (tileSize * mapHeight)
end
if map[x][y].y > mapY + (mapHeight * tileSize) - (tileSize / 2) then
map[x][y].y = map[x][y].y - (tileSize * mapHeight)
end
end
end
updateTilesetBatch()
end
function themap:load()
setupMap()
setupTileset()
updateTilesetBatch()
themap:moveMap(-150, 0)
end
return themap, tilesetBatch
```