Hi,
Completely new to game dev and defold. I use the Linker sample game as a basis.
What I try to achieve is to populate the board (starting with one object and adding another object every 2 seconds). Currently, thefunction update
send a message and the function on_message
trigger the function build_board
. It works.
But I really have any clue how to do for the next time the function build_board will be called, it will create an object at the position [1,0].
local function build_board()
local board = {}
math.randomseed(os.time())
local pos = vmath.vector3()
local x = 0
local y = 0
pos.x = edge + blocksize / 2 + blocksize * x
board[x] = {}
pos.y = top_edge - blocksize / 2 - blocksize * y
local color = colors[math.random(#colors)] -- Pick a random color
local id = factory.create("#airplane_factory", pos, null, { color = color })
board[x][y] = { id = id, x = x, y = y, color = color, type = type }
print(id)
return board
end
function update(self, dt)
self.timer = self.timer + dt
if self.timer >=2 then
local added = 0
msg.post("#", "reached2")
self.timer = 0
end
end
Thank you,
Vincent