okay, so I have gotten a start on this, and have gotten it to create a grid of tiles in the scrollview using data from my map file i created, but I’m running into some issues.
my problem is that the structure icons assigned to the tiles are not lined up with my tiles correctly. They seem to be about about 50 pixels off both x and y
here is my code
-- Create a new ScrollView widget:
local scrollView = widget.newScrollView{
width = 420,
height = 320,
scrollWidth = 1000,
scrollHeight = 1000,
friction = .75,
maskFile="mask-420x320.png",
hideBackground = true,
hideScrollBar = true,
listener = scrollViewListener
}
-- populate tiletype
local tileType = {}
tileType[1] = "blank.png"
tileType[2] = "agriculture.png"
tileType[3] = "farm.png"
tileType[4] = "industry.png"
tileType[5] = "factory.png"
tileType[6] = "energy.png"
tileType[7] = "powerplant.png"
tileType[8] = "commerce.png"
tileType[9] = "bank.png"
tileType[10] = "lab.png"
tileType[11] = "market.png"
tileType[12] = "barrack.png"
tileType[13] = "tavern.png"
tileType[14] = "monument.png"
tileType[15] = "kapital.png"
-- populate playerColor
local playerColor = {}
playerColor[1] = {255,255,255}
playerColor[2] = {157,173,249}
playerColor[3] = {255,115,115}
playerColor[4] = {122,217,114}
playerColor[5] = {252,254,117}
local typeId = 0
local defense = 0
-- populate scrollview
local grid = {}
for row = 1, 10 do -- 10 rows
grid[row] = {}
for col = 1, 10 do -- 10 columns
grid[row][col] = display.newGroup()
-- Create tile and insert it into grid
grid[row][col].tile = display.newRoundedRect(0,0,95,95,7)
grid[row][col].tile:setReferencePoint(display.TopLeftReferencePoint)
grid[row][col]:insert(grid[row][col].tile)
if mapTable[row][col][1] == 0 then
grid[row][col].tile.isVisible = false
end
-- Fill tile with correct player color
grid[row][col].tile:setFillColor( unpack( playerColor[mapTable[row][col][2] ] ) )
-- "unpack()" converts {x,y,z} into x,y,z
-- Paint a stoke line
grid[row][col].tile:setStrokeColor(140, 140, 140)
grid[row][col].tile.strokeWidth = 2
-- Insert Defense value into grid array
grid[row][col].defense = mapTable[row][col][3]
-- Insert Shield icon into grid array and hide it
grid[row][col].shield = display.newImageRect("shield.png", 95, 95)
grid[row][col].shield:setReferencePoint(display.TopLeftReferencePoint)
grid[row][col]:insert(grid[row][col].shield)
if mapTable[row][col][3] \<= 0 then
grid[row][col].shield.isVisible = false
end
grid[row][col].shield.x = grid[row][col].tile.x
grid[row][col].shield.y = grid[row][col].tile.y
-- Insert defenseText and hide it
defense = mapTable[row][col][3]
grid[row][col].defenseText = display.newText(defense, 12, 8, "Helvetica", 24)
grid[row][col]:insert(grid[row][col].defenseText)
if mapTable[row][col][3] \<= 0 then
grid[row][col].defenseText.isVisible = false
end
-- Insert structure icons into grid array
typeId = mapTable[row][col][1]
if typeId \>= 1 then
grid[row][col].structure = display.newImageRect( tileType[typeId], 95, 95 )
grid[row][col].structure:setReferencePoint(display.TopLeftReferencePoint)
grid[row][col]:insert(grid[row][col].structure)
grid[row][col].structure.x = grid[row][col].tile.x
grid[row][col].structure.y = grid[row][col].tile.y
end
-- Position tile
grid[row][col].x = (col - 1) \* 100
grid[row][col].y = (row - 1) \* 100
-- Print confirmation
print("Y = " .. row .. " X = " .. col .. " and Tile Type = " .. typeId)
-- Insert grid into scrollView
scrollView:insert( grid[row][col] )
I edited this code to reflect changes I’ve made, and put it inside the correct tags [import]uid: 170004 topic_id: 34899 reply_id: 138899[/import]